桌子,表格,表格垂直排列,乳胶

发布于 2024-10-01 06:43:59 字数 434 浏览 8 评论 0原文

好吧,这听起来很简单,但我花了几个小时谷歌搜索,但找不到解决方案,这并不复杂。 我想创建一个包含图像和文本的表格。我希望桌子的每一行都有相同的高度。我希望文本始终从顶部开始。 即,

\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}

根据我的直觉,星号(*)处的文本开头应该与aImage的顶部垂直对齐,但事实并非如此,我无法正确对齐。 添加 [b] 或 [t] 没有帮助。 我完全错了,因为我不可能是唯一想要这个的人。

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.
i.e.

\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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧话新听 2024-10-08 06:43:59

据我了解,问题在于 LaTeX 将包含的图形视为单行文本,该文本恰好延伸到该行上方相当多的位置,因此该行的顶部仍然只是基线上方的字体大小,而不是在图像的顶部,因此与其对齐效果不太好。

我通常解决这个问题的方法是将文本包装在合适的 parbox 中,类似这样

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

这里的要点是我将底部 parbox 与底部对齐图像,但然后在其底部添加垂直空间,以便垂直空间的底部对齐,并且文本在顶部很好地对齐。当然,您需要根据表格单元格的宽度自行确定宽度(此处为0.4\linewidth)和所需的垂直空间(此处为3\baselineskip)图像的高度,所以这个解决方案并不能真正推广到你可以宏观观察的东西。尽管如此,它在需要时使用起来相当简单,尽管它需要一些手动调整才能正确对齐。

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.

不气馁 2024-10-08 06:43:59

也许 TikZ 是一条可能的出路。可以使用 \node{\includegraphics{myfile.ext}} 将图形包含在 TikZ 节点中,然后可以绘制框或网格。文本节点可以在任何位置保存文本。如果您需要(足够的图片使其值得),您可以使用 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}

这不是一个完美的答案,它需要比许多 LaTeX 用户喜欢的更多调整。然而,这种灵活性可能会让您以“让某些东西发挥作用”的方式解决您的问题。

希望有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文