简体   繁体   中英

table, tabular, tabularx vertical alingment, latex

Ok, this sounds so easy, but I've spent hours googling and I just cant find a solution, that isn't to complicated. I want to create a table that has images and text in it. I want every row of the table to have the same height. And I want the text to always start at the top. ie

\begin{tabular}{l l}
some text & some text and some more text...\\ %both starting at the same height.
\includegraphics{aImage.eps} & (*)Some text...   %both starting at the same height.
\end{tabularx}

In my intuition the beginning of the text at the asterix(*) should be vertically aligned to the top of the aImage, but it isn't and I can't get it right. Adding [b] or [t] doesn't help. What did I get completely wrong, because I can't be the only person who wants this.

Perhaps TikZ is a possible way to go. A graphic can be included in a TikZ node with \\node{\\includegraphics{myfile.ext}} , then boxes can be drawn, or a grid. Text nodes can hold the text wherever you position them. If you need to (enough pics to make it worth it) you can create it with a loop using pgffor.

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\draw[step=2cm] (-4cm,0) grid (4cm,4cm);

\node at (-3cm,3cm) {Text};
\node at (-3cm,1cm) {includegraphics};

\end{tikzpicture}
\end{document}

Its not a perfect answer, it needs a little more tweaking than many LaTeX users like. However this flexiblity might get you around your problem, in a "just get something working" kind of way.

Hope it helps.

The problem, as I understand it, is that LaTeX treats the included graphic as a single line of text that just happens to extend quite a bit above the line, so the top of that line is still just the font's size above the baseline, not at the top of the image, so alignment with it isn't going to work very well.

The way I seem to have usually solved this is to wrap the text inside a suitable parbox , something like this

\includegraphics{aImage.eps} & \parbox[b]{0.4\linewidth}{(*)Some text\vspace{3\baselineskip}}

The point here is that I align the bottom parbox with the bottom of the image but then add vertical space to the bottom of it so that it's the bottom of the vertical space that gets aligned, and the text aligns nicely at the top. Of course, the width (here 0.4\\linewidth ) and the needed vertical space (here 3\\baselineskip ) you need to determine yourself based on the width of your table cell and the height of the image, so this solution doesn't really generalize to something you could just macro away. Still, it's reasonably simple to use whenever it's needed, even though it requires some hand-tuning to get the alignment right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM