2

I want to force the content of one of the cells in my table to overflow the cell width by a specified amount. With c columns, negative kerning does the trick. But I also want vertical alignment, and negative kerning no longer works with m columns.

Minimum working example:

\documentclass{article}

\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

%\begin{tabular}[h]{|M{1in}|M{1in}|M{1in}|}
\begin{tabular}[h]{|c|c|c|}
  \hline
  \rule{0.2in}{1in} &
  \rule{1in}{0.2in} &
  \rule{0.2in}{1in} \\
  \hline
  \rule{1in}{0.2in} &
  \rule{0.2in}{1in} &
  \rule{1in}{0.2in} \\
  \hline
  \rule{0.2in}{1in} &
  \kern-0.5in\rule{1.5in}{0.2in} &
  \rule{0.2in}{1in} \\
  \hline
\end{tabular}

\end{document}

enter image description here

The bottom middle cell shows what I mean. Toggle the commenting on the \begin{tabular} lines to see it fail with m columns. How can I get it to work?

Motivation: I have a column containing a bunch of images with similar, aligned content. Most of them are the same width, but one is wider because the extra space contains some additional information like labels. I want the extra space to be ignored so that the images remain well aligned in my document. I don't want to simply use left- or right-alignment, because that wastes the extra space in the other cells.

3

Use \makebox instead of the \kern:

\documentclass{article}

\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{tabular}[h]{|M{1in}|M{1in}|M{1in}|}
%\begin{tabular}[h]{|c|c|c|}
  \hline
  \rule{0.2in}{1in} &
  \rule{1in}{0.2in} &
  \rule{0.2in}{1in} \\
  \hline
  \rule{1in}{0.2in} &
  \rule{0.2in}{1in} &
  \rule{1in}{0.2in} \\
  \hline
  \rule{0.2in}{1in} &
  \makebox[1in][r]{\rule{1.5in}{0.2in}} &
  \rule{0.2in}{1in} \\
  \hline
\end{tabular}

\end{document}

Explanation: \makebox[1in][r]{\rule{1.5in}{0.2in}} puts the rule in a box of width 1in and right-aligns it in the box.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.