LaTeX 中表格中的自定义对齐文本

发布于 2024-08-19 14:05:30 字数 1057 浏览 4 评论 0原文

基本上,我想在 LaTeX 中生成下表(注意第二个单元格的“逗号对齐”):

----------------------------------------
| Header1 | Header2                    |
----------------------------------------
|    1    | "value 1"      , "value 2" |
|    2    | "one"          , "two"     |
|    3    | "abcdefheasal" , "ok"      |
----------------------------------------

我在 中生成上面表格的方式LaTeX 如下:

\begin{tabular}{|c|l|}
  \hline
  Header1 & Header2             \\
  \hline
  1 & ``value 1'' , ``value 2'' \\
  2 & ``one'' , ``two''         \\
  3 & ``abcdefheasal'' , ``ok'' \\
  \hline
\end{tabular} 

但显然,该代码生成以下内容(显然没有“逗号对齐”):

-----------------------------------
| Header1 | Header2               |
-----------------------------------
|    1    | "value 1" , "value 2" |
|    2    | "one" , "two"         |
|    3    | "abcdefheasal" , "ok" |
-----------------------------------

将后一个表格转换为表格的最佳方法是什么我想?即前者

Basically, I want to produce the following table in LaTeX (Notice the "comma alignment" of the second cell) :

----------------------------------------
| Header1 | Header2                    |
----------------------------------------
|    1    | "value 1"      , "value 2" |
|    2    | "one"          , "two"     |
|    3    | "abcdefheasal" , "ok"      |
----------------------------------------

The way I would produce the table above in LaTeX is as follows:

\begin{tabular}{|c|l|}
  \hline
  Header1 & Header2             \\
  \hline
  1 & ``value 1'' , ``value 2'' \\
  2 & ``one'' , ``two''         \\
  3 & ``abcdefheasal'' , ``ok'' \\
  \hline
\end{tabular} 

But obviously, that code produces the following (obviously without the "comma alignment") :

-----------------------------------
| Header1 | Header2               |
-----------------------------------
|    1    | "value 1" , "value 2" |
|    2    | "one" , "two"         |
|    3    | "abcdefheasal" , "ok" |
-----------------------------------

What is the best way to turn the latter table into the one I want? i.e. the former

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

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

发布评论

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

评论(2

流殇 2024-08-26 14:05:30

作为对 Martin B 答案的修改,请考虑使用 @ 符号来制作列分隔符:

\begin{tabular}{|c|l@{ , }l|}
  \hline
  Header1 & \multicolumn{2}{l|}{Header2}  \\
  \hline
  1 & ``value 1'' & ``value 2'' \\
  2 & ``one'' & ``two''         \\
  3 & ``abcdefheasal'' & ``ok'' \\
  \hline
\end{tabular}

另请注意,multicolumn 中需要一个额外的管道来绘制垂直线第一行。

As a modification to Martin B's answer, consider using the @ sign to make a column separator:

\begin{tabular}{|c|l@{ , }l|}
  \hline
  Header1 & \multicolumn{2}{l|}{Header2}  \\
  \hline
  1 & ``value 1'' & ``value 2'' \\
  2 & ``one'' & ``two''         \\
  3 & ``abcdefheasal'' & ``ok'' \\
  \hline
\end{tabular}

Also note that an extra pipe is needed in the multicolumn to draw the vertical line on the first row.

稍尽春風 2024-08-26 14:05:30

我建议使用三列表,然后合并第二列和第三列的标题,如下所示:

\begin{tabular}{|c|ll|}
  \hline
  Header1 & \multicolumn{2}{l}{Header2} \\  
  \hline  
  1 & ``value 1''      & , ``value 2''  \\  
  2 & ``one''          & , ``two''      \\  
  3 & ``abcdefheasal'' & , ``ok''       \\  
  \hline
\end{tabular}

I would suggest using a three-column table, then merging the header of the second and third column, as follows:

\begin{tabular}{|c|ll|}
  \hline
  Header1 & \multicolumn{2}{l}{Header2} \\  
  \hline  
  1 & ``value 1''      & , ``value 2''  \\  
  2 & ``one''          & , ``two''      \\  
  3 & ``abcdefheasal'' & , ``ok''       \\  
  \hline
\end{tabular}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文