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.

I am working in a minipage, because I want two columns next to each other in landscape mode.

In the first column I would like to place a figure, and then a tabular. I am scaling the tabular to exactly fit the minipage. This is roughly the outline:

\newpage
\begin{minipage}{0.50\textwidth}
\begin{center}
\resizebox{\columnwidth}{!}{%
% latex table generated in R 2.14.1 by xtable 1.6-0 package
% Thu Nov  8 13:31:32 2012
\begin{tabular}
...
\end{tabular}%
}
\end{center}
\end{minipage}
\begin{minipage}{0.50\textwidth}
\end{minipage}

What I now would like to do is plot the remaining figure in exactly the correct proportions to fill the remainder of the page - the width is fairly easy, but what is the height? The problem is also that I don't know the number of rows of the table in advance.

So I need some way to determine the height of the tabular, subtract it from the textheight, to obtain my remaining space for the figure.

\settoheight unfortunately only works on text.

share|improve this question
4  
as with any latex construct you can put it in a box and measure the \ht of the box, which is exactly the definition of \settoheight. I'm not sure why you say that only works on text, the box measurement doesn't know what is inside the box, it can be text tables, graphics, anything that latex can typeset. –  David Carlisle Nov 8 '12 at 14:04
1  
Also if you want your two minipages to fit side by side you need a % after \end{minipage} as you have a word space between them and you can not get two 0.5\textwidth boxes and a word space on one line. –  David Carlisle Nov 8 '12 at 14:06
    
@DavidCarlisle: Thanks! The reason I thought it wouldn't work was the help where it specifically mentions text. –  Cookie Nov 8 '12 at 15:04
    
LaTeX thinks more or less anything is text: a table is just a big letter.... –  David Carlisle Nov 8 '12 at 15:15

3 Answers 3

up vote 2 down vote accepted

You have to remember that \settoheight measures the height, but tabular environments also have a depth; so we need to take also the depth into account. Here's a proposal; the total height of the (resized) table is stored in the register \tableheight:

\documentclass{article}
\usepackage[demo]{graphicx}
\newsavebox{\tablebox}
\newlength{\tableheight}
\newenvironment{resizedtabular}[1]
 {\begin{lrbox}{\tablebox}\begin{tabular}{#1}}
 {\end{tabular}\end{lrbox}%
  \sbox{\tablebox}{\resizebox{\textwidth}{!}{\usebox{\tablebox}}}%
  \global\tableheight=\ht\tablebox
  \global\advance\tableheight\dp\tablebox
  \usebox{\tablebox}}


\begin{document}

\noindent
\begin{minipage}{0.50\textwidth}
\centering
\begin{resizedtabular}{lll}
abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi
\end{resizedtabular}
\end{minipage}%
\begin{minipage}{0.50\textwidth}
\includegraphics[width=\textwidth,height=\tableheight]{a}
\end{minipage}

\bigskip

\noindent
\begin{minipage}{0.50\textwidth}
\centering
\begin{resizedtabular}{llllll}
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi \\
abcabcabc & defdefdef & ghighighi & abcabcabc & defdefdef & ghighighi
\end{resizedtabular}
\end{minipage}%
\begin{minipage}{0.50\textwidth}
\includegraphics[width=\textwidth,height=\tableheight]{a}
\end{minipage}

\end{document}

enter image description here

share|improve this answer
    
Perfect, thank you –  Cookie Nov 9 '12 at 10:48

Does something like the following help:

\documentclass{article}

\newcommand{\testtbl}{%
\begin{tabular}{|c|c|}
test & test\\
test & test
\end{tabular}
}
\newcommand{\ntabht}{%
  \setbox0=\hbox{\testtbl} \the\ht0%
}

\begin{document}
\ntabht
\end{document}

Notice that this will print the height of the table which in this case is 14.5pt.

share|improve this answer

This is to answer

\settoheight unfortunately only works on text.

Code:

\documentclass{article}

\newlength{\mylength}
\settoheight{\mylength}{%
\begin{tabular}{|c|c|}
test & test\\
test & test\\
test & test\\
test & test
\end{tabular}
}

\begin{document}
\the\mylength
\end{document}

The result is 26.5pt. Hence \settoheight works!

share|improve this answer

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.