2012年10月11日星期四

Make LaTeX floats behave better

LaTeX floating objects can easily give me headaches. Today I saw this link:

http://mintaka.sdsu.edu/GF/bibliog/latex/floats.html

It provides a set of really neat commands to put in the beginning of your document, and all of a sudden the floats behave so nicely now :-)


% Alter some LaTeX defaults for better treatment of figures:
    % See p.105 of "TeX Unbound" for suggested values.
    % See pp. 199-200 of Lamport's "LaTeX" book for details.
    %   General parameters, for ALL pages:
    \renewcommand{\topfraction}{0.9} % max fraction of floats at top
    \renewcommand{\bottomfraction}{0.8} % max fraction of floats at bottom
    %   Parameters for TEXT pages (not float pages):
    \setcounter{topnumber}{2}
    \setcounter{bottomnumber}{2}
    \setcounter{totalnumber}{4}     % 2 may work better
    \setcounter{dbltopnumber}{2}    % for 2-column pages
    \renewcommand{\dbltopfraction}{0.9} % fit big float above 2-col. text
    \renewcommand{\textfraction}{0.07} % allow minimal text w. figs
    %   Parameters for FLOAT pages (not text pages):
    \renewcommand{\floatpagefraction}{0.7} % require fuller float pages
 % N.B.: floatpagefraction MUST be less than topfraction !!
    \renewcommand{\dblfloatpagefraction}{0.7} % require fuller float pages

 % remember to use [htp] or [htpb] for placement

2012年10月5日星期五

LaTeX centering a table that is larger than text width

Had this problem today with my thesis proposal, and luckily the solution is not hard to find:
http://mathandprogramming.blogspot.com/2011/07/latex-centering-table-larger-than.html

You basically need to use a package called chngpage and add an environment surrounding the table:

% allows for temporary adjustment of side margins
\usepackage{chngpage}

\begin{table}
    \begin{adjustwidth}{-.5in}{-.5in}  
        \begin{center}
        \begin{tabular}{|c|}
           % really wide table here
        \end{tabular} 
        \caption{This way the caption will also be the same width as the table, wider than the other text. }
        \label{myTable}
        \end{center}
    \end{adjustwidth}
\end{table}