Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Why when I try to re-scale a tikz figure using \resizebox the baseline is shifted up (regardless of how small the scale factor is), and two horizontal floats are not aligned properly.

not aligned

\documentclass[twocolumn]{article}

\usepackage{tikz}
\usepackage{graphicx}
\usepackage{subfig}

\pagestyle{empty}

\begin{document}
\begin{figure}
\centering
\begin{tabular}{cc}%
\subfloat[]{%
\fbox{
\resizebox{0.5\linewidth}{!}{%
\begin{tikzpicture}
\node {a};%
\end{tikzpicture}%
}%end resize
}%fbox
}&%end subfloat
\subfloat[]{%
\begin{tabular}{c|cccc}%
  & 0 & 1 & \dots & n\\\hline
a & & & &\\
b & & & &\\
c & & & &\\
\dots & & & &\\
d & & & &\\
\end{tabular}%
}%end subfloat
\end{tabular}%
\caption{Why resizebox shifts the baseline up?}
\end{figure}
\end{document}
share|improve this question
1  
I think you want to avoid the spurious space after \fbox{ by adding % there as well. Note that with the adjustbox package you can simply write \adjustbox{width=0.5\linewidth,fbox}{..} or \begin{adjustbox}{width=0.5\linewidth,fbox} .. \end{adjustbox} and easily add more modifiers. –  Martin Scharrer Jan 3 '13 at 9:33

1 Answer 1

up vote 8 down vote accepted

The problem is not the baseline of the \resizebox but the baseline of the tabular which is on its center by default. So changing the baseline of the tabular with [b] solves this issue:

\documentclass[twocolumn]{article}

\usepackage{tikz}
\usepackage{graphicx}
\usepackage{subfig}

\pagestyle{empty}

\begin{document}
\begin{figure}
\centering
\begin{tabular}{cc}%
\subfloat[]{%
\fbox{
\resizebox{0.5\linewidth}{!}{%
\begin{tikzpicture}
\node {a};%
\end{tikzpicture}%
}%end resize
}%fbox
}&%end subfloat
\subfloat[]{%
\begin{tabular}[b]{c|cccc}% === [b] added here ===
  & 0 & 1 & \dots & n\\\hline
a & & & &\\
b & & & &\\
c & & & &\\
\dots & & & &\\
d & & & &\\
\end{tabular}%
}%end subfloat
\end{tabular}%
\caption{Why resizebox shifts the baseline up?}
\end{figure}
\end{document}

enter image description here

Addendum 2013-01-04: As user adn has found out, the captions are still not perfectly aligned. (See comments below.) A possible solution would be switching to the subcaption package resp. its \subcaptionbox command:

\documentclass[twocolumn]{article}

\usepackage{tikz}
\usepackage{graphicx}
\usepackage{subcaption}

\pagestyle{empty}

\begin{document}
\begin{figure}
\centering
\begin{tabular}{cc}%
\subcaptionbox{}{%
\fbox{
\resizebox{0.5\linewidth}{!}{%
\begin{tikzpicture}
\node {a};%
\end{tikzpicture}%
}%end resize
}%fbox
}&%end subcaptionbox
\subcaptionbox{}{%
\begin{tabular}{c|cccc}%
  & 0 & 1 & \dots & n\\\hline
a & & & &\\
b & & & &\\
c & & & &\\
\dots & & & &\\
d & & & &\\
\end{tabular}%
}%end \subcaptionbox
\end{tabular}%
\caption{Why resizebox shifts the baseline up?}
\end{figure}
\end{document}

Please note that changing the baseline of the inner tabular (with [b]) is not necessary here since a \subcaptionbox always has its baseline between content and caption, and therefore the two \subcaptionboxes are already aligned by default.

share|improve this answer
    
Thanks, I didn't know that... :) –  adn Jan 3 '13 at 9:29
    
Quick question, is it me or the table is a little bit shifted down in comparison to the tikzpicture? –  adn Jan 4 '13 at 1:35
    
Can't confirm that. Even if I use the magnifying lens of TeXworks the bottom rule of the picture is exactly on a horizontal line with the pixel at the bottom of the tabular. –  Axel Sommerfeldt Jan 4 '13 at 4:59
    
I was talking about the captions (a) and (b), maybe it is just a visual effect. –  adn Jan 4 '13 at 5:27
1  
When using my subcaption package instead of subfig (and replacing \subfloat with \subcaptionbox) the effect has gone. So I assume it's a bug in subfig!? Shall I add the subcaption code to my answer? –  Axel Sommerfeldt Jan 4 '13 at 7:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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