From: October 17, 2019, 18:03

This is a trick I’ve been using in LaTeX recently when laying out grids of figures.

If I want to layout columns with specific width in LaTeX I can use m{width} or p{width} or b{width} as the column specifiers (rather than the typical l c or r). m creates vertically centered entries, where as p and b align to the top or bottom respectively.

However, if my goal is to fit the grid precisely into the width of the page (particularly useful in 2-column papers, IME), using a width of m{0.5\linewidth} (for two columns) will fail due to additional padding on the left and right of the cell content. This will lead to an “overfull hbox”. To fix this, we can use an additional specifier @{} on either side of the column spec which removes the padding.

Finally, if we want our content centered within the cell, as I often find prefereable for grid figure layouts, we can also add >{\centering}, which adds \centering to the beginning of the contents of each cell. Alternatively, you could use \raggedleft/\hfill for right alignment. This part requires the array package.

An example with two columns:

    \begin{tabular}{
        @{}>{\centering}m{0.5\linewidth}@{}
        @{}>{\centering}m{0.5\linewidth}@{}
    }
        \includegraphics{...} & \includegraphics{...} \tabularnewline
        \includegraphics{...} & \includegraphics{...}
    \end{tabular}

Comments

Load comments