简体   繁体   English

table,tabular,tabularx vertical alingment,latex

[英]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. 在我的直觉中,星号(*)处的文本的开头应该垂直对齐到aImage的顶部,但它不是,我无法正确。 Adding [b] or [t] doesn't help. 添加[b]或[t]没有帮助。 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. 也许TikZ是一种可行的方式。 A graphic can be included in a TikZ node with \\node{\\includegraphics{myfile.ext}} , then boxes can be drawn, or a grid. 可以使用\\node{\\includegraphics{myfile.ext}}在TikZ节点中包含图形,然后可以绘制框或网格。 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. 如果你需要(足够的图片使它值得)你可以使用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. 它不是一个完美的答案,它需要比许多LaTeX用户更多的调整。 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. 根据我的理解,问题是LaTeX将包含的图形视为单行文本,恰好在线上方延伸了一点,所以该行的顶部仍然只是字体大小高于基线,而不是在图像的顶部,因此与它的对齐不会很好地工作。

The way I seem to have usually solved this is to wrap the text inside a suitable parbox , something like this 我似乎通常解决这个问题的方法是将文本包装在合适的parbox ,就像这样

\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. 这里的要点是我将底部parbox与图像的底部对齐,然后在其底部添加垂直空间,使其垂直空间的底部对齐,文本在顶部对齐。 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. 当然,宽度(这里是0.4\\linewidth )和所需的垂直空间(这里是3\\baselineskip )你需要根据表格单元格的宽度和图像的高度来确定自己,所以这个解决方案并没有真正概括你可能只是宏观的东西。 Still, it's reasonably simple to use whenever it's needed, even though it requires some hand-tuning to get the alignment right. 尽管如此,在需要时使用它仍然相当简单,即使它需要一些手动调整才能使对齐正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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