使用 seqsplit 和多列

使用 seqsplit 和多列

我想创建一个长表,其标题居中,列左对齐或右对齐。感谢我之前的问题: 在长表中右对齐两列以及它的出色答案,我制作了这个示例文档:

\documentclass{article}
\usepackage{array}
\usepackage{seqsplit}
\usepackage{longtable}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}

\begin{document}
\begin{longtable}{|L{3.32cm}|R{3.97cm}|R{3.14cm}|L{3.57cm}|}
\hline
\multicolumn{1}{|c|}{ header1 } & \multicolumn{1}{c|}{header2} & \multicolumn{1}{c|}{ \seqsplit{The\_header3\_is\_longer\_than\_expected} } & \multicolumn{1}{c|}{What\_would\_happen\_if\_header4} \\
\hline
\endhead
\hline
some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment \\
some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment \\
some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment \\
some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment \\
\end{longtable}
\end{document}

问题在于,当达到设置的宽度时,seqsplit 不会执行其工作并拆分长单词。请参阅:

Latex 示例

答案1

您不需要,\multicolumn因为列被声明为p1:使用\centering并只记得添加\arraybackslash最后一列(或用 结束该行)\tabularnewline

\documentclass{article}
\usepackage{array}
\usepackage{seqsplit}
\usepackage{longtable}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} % may come handy
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}

\begin{document}
\begin{longtable}{|L{3.32cm}|R{3.97cm}|R{3.14cm}|L{3.57cm}|}
\hline
\centering header1 &
  \centering header2 &
  \centering \seqsplit{The\_header3\_is\_longer\_than\_expected} & 
  \centering\arraybackslash \seqsplit{What\_would\_happen\_if\_header4} \\
\hline
\endhead
\hline
some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment \\
some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment \\
some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment \\
some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment & some text goes here to illustrate the alignment \\
\end{longtable}
\end{document}

在此处输入图片描述

答案2

这不是问题seqsplit。您明确指出latex您的标题是居中线(c)。它按您的要求执行。您需要将多列类型设为p{...}latex将其拆分。

相关内容