3

I use three minipages so to make a table and two images be placed next to each other and although the images are in the right place the table is placed much lower producing an ugly result. Why is that happening? How can I fix it?

\begin{minipage}[t]{5cm}
\begin{tabular}{|c|c|c|}
\hline
$V_{c}(Low)$ & $mV$ & $0$\\
\hline
$V_{c}(High)$ & $V$ & $5.6$\\
\hline
$T_{d}$ & $ns$ & $30$\\
\hline
$T_{r}$ & $ns$ & $30$\\
\hline 
$T_{sd}$ & $ns$ & $780$\\
\hline 
$T_{f}$ & $ns$ & $240$\\
\hline 
$F_{max}$ & $kHz$ & $570$\\
\hline
\end{tabular}
\end{minipage}
\begin{minipage}[t]{5cm}
\includegraphics[width=\textwidth]{A1.JPG}
\end{minipage}
\begin{minipage}[t]{5cm}
\includegraphics[width=\textwidth]{A2.JPG}
\end{minipage}
4
  • The \abovebaseline and \belowbaseline macros of stackengine could be of use here. With these, you don't specify how much to move the item up or down, but rather specify where you want it to end up, relative to the baseline. Mar 17, 2014 at 15:34
  • Did any of the answers below solve your problem? If not, can you explain what is missing? Mar 25, 2014 at 12:18
  • Yes they did. The only thing I can't quite understand is why I had to use some other way and my code didn't work aligning perfectly the table with the images, considering that as it is mentioned here a table is a sort of a minipage.
    – Adam
    Mar 27, 2014 at 1:33
  • @Adam I edited my answer with an (attempted) explanation and another way of doing this. Also, to make sure people are notified of comments here, write @<username> as I did here. (The person who owns the post is always notified, but not everyone else.) Mar 27, 2014 at 7:42

3 Answers 3

4

Why your code doesn't work.

This has to do with how this vertical alignment actually works. Consider first the following code and its output:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
Some text then a table \begin{tabular}{c}
1 \\2 \\ 3 \\ 4
\end{tabular}
then some more text and an image \includegraphics[width=2cm]{example-image-10x16}.    
\end{document}

enter image description here

The point of this is how the table and image is placed relative to the baseline of the surrounding text -- the tabular is vertically centred, the image is placed on the baseline, and so sticks above the line.

Now what the t/b position specifier for the minipages refer to is not actually the top/bottom edge of the minipage, as I understand it, but the baseline of the first/last line of text in the minipage. In the minipage with the table, the baseline is in the middle of the table, as you can see from the image above. But in the minipages with the images, the baseline is at the bottom of the image. As a result, the bottom of the images are aligned with the middle of the table.

Suggestion 1

As suggested by daleif, I removed the minipage for the tabular in the below code.

If you set the alignment of the right minipages to center it looks better, i.e.

\begin{minipage}[c]{5cm}

The tabular has c as alignment by default.

To top-align them, you can set the position of both tabular and minipages to t, and set the inner position (third optional argument) of the minipages with the images to b. That is, you'll have

\begin{tabular}[t]{...}

for the table and

\begin{minipage}[t][][b]{5cm}

for the minipages.

Suggestion 2

If you add \usepackage[export]{adjustbox} you can change the vertical alignment of images, relative to the baseline, with the optional argument valign=<t/c/b> to \includegraphics. Then you can ditch the minipages altogether.

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[export]{adjustbox}
\begin{document}   
\begin{tabular}{>{$}c<{$} s S }
\toprule
V_{c}(\text{Low}) & \milli\volt & 0\\
V_{c}(\text{High}) & \volt & 5.6\\
T_{d} & \nano\s & 30\\
T_{r} & \nano\s & 30\\
T_{sd} & \nano\s & 780\\
T_{f} & \nano\s & 240\\
F_{\text{max}} & \kilo\hertz & 570\\
\bottomrule
\end{tabular}\hspace{1em}
\includegraphics[width=5cm,valign=c]{example-image-a}
\includegraphics[width=5cm,valign=c]{example-image-b}

\end{document}

Some notes about the table.

Not really part of the question, but I added a suggestion for how you could write the table in the code below, you see the result in the image.

The column specification has been changed to {>{$}c<{$} s S }. When loading the array package you can use >{}/<{} to insert stuff at the beginning/end of the cell, by doing the above the effect is that each cell is set in math mode. That saves you some typing.

For the second column, note that units should generally not be written in italics. You could simply remove all the math mode, and it would be a lot better. Here I used an s column from siunitx, which allows one to use the unit macros from siunitx to typeset the units.

The final column is an S column, also from siunitx, which aligns the numbers at the decimal marker. Not sure if is an improvement in this case, but I thought I'd add it as a tip.

In the first column, you'll notice I set words 'Low' and 'High' and 'max' in text mode. This is mostly a question of convention I suppose, but I think descriptive words, as opposed to variable names, should not be italic. I also removed all the vertical lines, and added a thicker horizontal line (from booktabs) above and below. It makes the table less cluttered.

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{>{$}c<{$} s S }
\toprule
V_{c}(\text{Low}) & \milli\volt & 0\\
V_{c}(\text{High}) & \volt & 5.6\\
T_{d} & \nano\s & 30\\
T_{r} & \nano\s & 30\\
T_{sd} & \nano\s & 780\\
T_{f} & \nano\s & 240\\
F_{\text{max}} & \kilo\hertz & 570\\
\bottomrule
\end{tabular}\hspace{1em}
\begin{minipage}[c]{5cm}
\includegraphics[width=\textwidth]{example-image-a}
\end{minipage}
\begin{minipage}[c]{5cm}
\includegraphics[width=\textwidth]{example-image-b}
\end{minipage}

\vspace{2cm}

\begin{tabular}[t]{>{$}c<{$} s S }
\toprule
V_{c}(\text{Low}) & \milli\volt & 0\\
V_{c}(\text{High}) & \volt & 5.6\\
T_{d} & \nano\s & 30\\
T_{r} & \nano\s & 30\\
T_{sd} & \nano\s & 780\\
T_{f} & \nano\s & 240\\
F_{\text{max}} & \kilo\hertz & 570\\
\bottomrule
\end{tabular}\hspace{1em}
\begin{minipage}[t][][b]{5cm}
\includegraphics[width=\textwidth]{example-image-a}
\end{minipage}
\begin{minipage}[t][][b]{5cm}
\includegraphics[width=\textwidth]{example-image-b}
\end{minipage}

\end{document}

enter image description here

3

One can avoid the minipages altogether, using \abovebaseline and \belowbaseline of the stackengine package. Note the syntax at the end of the MWE. In this case, I saved each item in its own stackbox only so that, if the centered output was required, additional calculation was required using the box heights. Otherwise, the columns could have been output directly with the syntax shown.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{stackengine}
\parskip 1em
\begin{document}
\savestack{\colA}{
\begin{tabular}[b]{|c|c|c|}
\hline
$V_{c}(Low)$ & $mV$ & $0$\\
\hline
$V_{c}(High)$ & $V$ & $5.6$\\
\hline
$T_{d}$ & $ns$ & $30$\\
\hline
$T_{r}$ & $ns$ & $30$\\
\hline 
$T_{sd}$ & $ns$ & $780$\\
\hline 
$T_{f}$ & $ns$ & $240$\\
\hline 
$F_{max}$ & $kHz$ & $570$\\
\hline
\end{tabular}}

\savestack{\colB}{\includegraphics[width=5cm,height=4cm]{A1.JPG}}

\savestack{\colC}{\includegraphics[width=5cm,height=2.5cm]{A2.JPG}}

\colA\ \abovebaseline[.5\ht\colAcontent-.5\ht\colBcontent]{\colB}\ 
  \abovebaseline[.5\ht\colAcontent-.5\ht\colCcontent]{\colC}

\colA\ \colB\ \colC

\belowbaseline{\colA}\ \belowbaseline{\colB}\ \belowbaseline{\colC}
\end{document}

enter image description here

1

tabular is already a sort of minipage (you may want to use \begin{tabular[t]{...}). By default it has it baseline in the middle, the surrounding minipage does not alter this as the tabular behaves as a single line (sort of). The images are aligned on the base like and it mush taller than that.

You might want to play with the adjustbox package, it has many useful features for aligning stuff.

Also a small plea: please post something we can copy'n'paste and use without editing it. You have no preamble, and we of course do not have your images. For images you could use \rule{length}{length}.

2
  • Thank you. You are right about the editing part so I won't neglect it the the next time. But sorry I didn't understand why all three items didn't aligh horizontally if the table is a sort of a minipage but the latter went down in the page even though the images in the minipages were up and aligned.
    – Adam
    Mar 17, 2014 at 15:35
  • See what happens if you use \begin{tabular}[t]{...}, and then what happens if you change all four [t] to [b]
    – daleif
    Mar 17, 2014 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .