乳胶填充/边缘地狱
我已经与乳胶桌搏斗太久了。我需要一个具有居中标题和包含可能环绕的文本的正文单元格的表格。由于环绕要求,我使用 p{xxx} 而不是 l 来指定单元格宽度。这导致的问题是单元格内容没有左对齐,因此看起来像间隔的垃圾。为了解决这个问题,我对每个单元格使用 \flushleft 。这确实使内容左对齐,但在单元格内容的上方和下方放置了大量空白。有没有办法阻止 \flushleft (或 \center )以停止添加大量的垂直空白?
谢谢
\begin{landscape}
\centering
% using p{xxx} here to wrap long text instead of overflowing it
\begin{longtable}{ | p{4cm} || p{3cm} | p{3cm} | p{3cm} | p{3cm} | p{3cm} |}
\hline
&
% these are table headings. the \center is causing a ton of whitespace as well
\begin{center} \textbf{HTC HD2} \end{center} &
\begin{center} \textbf{Motorola Milestone} \end{center} &
\begin{center} \textbf{Nokia N900} \end{center} &
\begin{center} \textbf{RIM Blackberry Bold 9700} \end{center} &
\begin{center} \textbf{Apple iPhone 3GS} \end{center} \\
\hline
\hline
% using flushleft here to left-justify, but again it is causing a ton of white space above and below cell contents.
\begin{flushleft}OS / Platform \end{flushleft}&
\begin{flushleft}Windows Mobile 6.5 \end{flushleft}&
\begin{flushleft}Google Android 2.1 \end{flushleft}&
\begin{flushleft}Maemo \end{flushleft}&
\begin{flushleft}Blackberry OS 5.0 \end{flushleft}&
\begin{flushleft}iPhone OS 3.1 \end{flushleft} \\
\hline
编辑:
感谢到目前为止的回答。我以为我找到了一个可行的解决方案,但这些问题仍然存在:
- 使用 \raggedright 可以阻止长单词被连字符连接。当一个单元格包含一堆只有一个单词的行时,这看起来很糟糕。
仅当以空行结束时,使用 \raggedright 才有效。这会导致每个单元格的底部都有一个完全空白的行。这是我一开始就想避免的。
{显示} & {\raggedright 4.3 英寸,800 x 400 分辨率} & {\raggedright 3.7 英寸,854 x 480 分辨率} & {\raggedright 3.5 英寸,800 x 480 分辨率} & {\raggedright 2.44 英寸,320 x 480 分辨率} & {\raggedright 3.5 英寸,480 x 320 分辨率} \\ \h行
I have been wrestling with a latex table for far too long. I need a table that has has centered headers, and body cells that contain text that may wrap around. Because of the wrap-around requirement, i'm using p{xxx} instead of l for specifying cell widths. The problem this causes is that cell contents are not left justified, so the look like spaced-out junk. To fix this problem I'm using \flushleft for each cell. This does left justify contents, but puts in a ton of white space above and below the contents of the cell. Is there a way to stop \flushleft (or \center for that matter) to stop adding copious amounts of verical whitespace?
thanks
\begin{landscape}
\centering
% using p{xxx} here to wrap long text instead of overflowing it
\begin{longtable}{ | p{4cm} || p{3cm} | p{3cm} | p{3cm} | p{3cm} | p{3cm} |}
\hline
&
% these are table headings. the \center is causing a ton of whitespace as well
\begin{center} \textbf{HTC HD2} \end{center} &
\begin{center} \textbf{Motorola Milestone} \end{center} &
\begin{center} \textbf{Nokia N900} \end{center} &
\begin{center} \textbf{RIM Blackberry Bold 9700} \end{center} &
\begin{center} \textbf{Apple iPhone 3GS} \end{center} \\
\hline
\hline
% using flushleft here to left-justify, but again it is causing a ton of white space above and below cell contents.
\begin{flushleft}OS / Platform \end{flushleft}&
\begin{flushleft}Windows Mobile 6.5 \end{flushleft}&
\begin{flushleft}Google Android 2.1 \end{flushleft}&
\begin{flushleft}Maemo \end{flushleft}&
\begin{flushleft}Blackberry OS 5.0 \end{flushleft}&
\begin{flushleft}iPhone OS 3.1 \end{flushleft} \\
\hline
Edit:
Thanks for the answers so far. I thought I found a solution that works, but these problems still exist:
- using \raggedright stops long words from being hyphenated. This looks pretty bad when a cell contains a bunch of lines with only one word in them.
using \raggedright only works if you end it with a blank line. This causes every cell to have a completely blank line at the bottom of it. This was what i was trying to avoid in the first place.
{Display} & {\raggedright 4.3 inch, 800 x 400 resolution} & {\raggedright 3.7 inch, 854 x 480 resolution} & {\raggedright 3.5 inch, 800 x 480 resolution} & {\raggedright 2.44 inch, 320 x 480 resolution} & {\raggedright 3.5 inch, 480 x 320 resolution} \\ \hline
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你应该可以只指定你想要的身体细胞的格式和
仅将标题更改为以
multicolumn
居中。这样你就不会必须像你现在一样弄乱太多的细胞。
You should be fine to just specify how you want the body cells formated and
change only the headers to centered with
multicolumn
. That way you don'thave to mess with too many cells like you do right now.
这不是最优雅的解决方案,但
\centering
和\raggedright
命令对应于center
和flushleft
环境,并且不要随着利润的增加而增加。如果我遇到更好的解决方案,我会发布它,但我认为这可以工作。
Not the most elegant solution, but the
\centering
and\raggedright
commands corresponds to thecenter
andflushleft
environments and don't come with the increased margins.If I come across a nicer solution I will post it, but this could work I think.
以@honk的例子为基础,我想你会想要这样的:
\documentclass{article}
单词仍然不会被连字符连接,但这应该可以解决你遇到的空行问题。
Building on @honk's example, i think you'd want this:
\documentclass{article}
Words still won't be hyphenated, but this should solve the blank line problem you're having.
不要在列对齐规范中使用 p 选项,而是使用 l。然后在每个标题中使用
\hfill Somephone \hfill
,并在每个正文单元中使用\vbox to 3cm {About text}
。这样做应该最大限度地减少多余的填充。Don't use p options in the column alignment specification, but use l instead. Then in each heading, use
\hfill Somephone \hfill
, and in each body cell, use\vbox to 3cm {About text}
. Doing so should minimise excess padding.