两列嵌套列表

两列嵌套列表

我正在制作一个与 leandriis 的这个答案非常相似的列表https://tex.stackexchange.com/a/498031/238485但现在想在列表中插入一个列表,即使其嵌套。在下图中,我想用下面的列表(从“关于”到“电子邮件”)替换文本“替换我”。我用来制作这个的代码可以在下面找到。谢谢!

在此处输入图片描述

\documentclass{article}
\usepackage{xltabular}
\usepackage{xcolor}
\begin{document}

\begin{xltabular}{\textwidth}{@{}r|>{}X@{}}
2017 -- 2019 & \textbf{Company 1} \\

                    & replace me \\
\multicolumn{2}{l}{}\\
2015      & \textbf{Company 2} \\
   \textcolor{white}{2017 -- 2019}                 & some text \\
                    & some text \\
\multicolumn{2}{l}{}\\
\end{xltabular}

\begin{xltabular}{\textwidth}{@{}r>{}X@{}}
About: & some text some text some text some text some text \\
          Role:       & some text some text some text
 some text some text
 some text some text some text
 some text some text some text
 some text some text some text 
 some text \\
           Contact:         & some text \\
            Email:    & some text \\
\multicolumn{2}{l}{}\\
\end{xltabular}


\end{document}

答案1

这里有三种不同的方法来实现以下输出:

在此处输入图片描述

选择哪一个取决于表格的实际内容。第一个版本使用了xltablar3 列,而不是 2 列。此解决方案特别有用,因为它不需要手动计算列宽。此解决方案在某种程度上仅限于“公司 1”下方的“一些文本”仅占用一行而不是多行。

另外两个建议使用longtable并手动计算列宽,如果您需要在“公司 2”下面的“某些文本”中自动换行,也可以使用这两个建议。第一个建议也使用了 3 列,如果您的表格中包含的遵循“公司 1”样式的条目多于遵循“公司 2”样式的条目,则该建议尤其有用。第二个基于longtable的建议仅使用两列与嵌套相结合,tabular如果您的表格中包含的遵循“公司 2”样式的条目更多,则该建议可能更有用。

\documentclass{article}
\usepackage{xltabular}

\usepackage{longtable}
\usepackage{array}
\usepackage{calc}

\begin{document}

\begin{xltabular}{\textwidth}{@{}r|rX@{}}
2017 -- 2019 & \multicolumn{2}{l}{\textbf{Company 1}} \\
             & About:   & some text some text some text some text some text \\
             & Role:    & some text some text some text  some text some text some text some text some text some text some text some text some text some text some text some text \\
             & Contact: & some text \\
             & Email:   & some text \\
\multicolumn{2}{l}{}\\
2015         & \multicolumn{2}{l}{\textbf{Company 2}} \\
             & \multicolumn{2}{l}{some text} \\
             & \multicolumn{2}{l}{some text some text some text some text} \\
\end{xltabular}



\newlength{\firstcolwidth}
\newlength{\secondcolwidth}
\newlength{\thirdcolwidth}
\newlength{\combinedcolwidth}

\setlength{\firstcolwidth}{\widthof{2017 -- 2019}}
\setlength{\secondcolwidth}{\widthof{Contact:}}
\setlength{\thirdcolwidth}{\linewidth-\firstcolwidth-\secondcolwidth-4\tabcolsep-\arrayrulewidth}
\setlength{\combinedcolwidth}{\secondcolwidth+\thirdcolwidth+2\tabcolsep}


\begin{longtable}{@{}wr{\firstcolwidth}|wr{\secondcolwidth}p{\thirdcolwidth}@{}}
2017 -- 2019 & \multicolumn{2}{l}{\textbf{Company 1}} \\
             & About:   & some text some text some text some text some text \\
             & Role:    & some text some text some text  some text some text some text some text some text some text some text some text some text some text some text some text \\
             & Contact: & some text \\
             & Email:   & some text \\
\multicolumn{2}{l}{}\\
2015         & \multicolumn{2}{l}{\textbf{Company 2}} \\
             & \multicolumn{2}{p{\combinedcolwidth}@{}}{some text some text some text some text some text some text some text some text some text some text some text some text} \\
             & \multicolumn{2}{p{\combinedcolwidth}@{}}{some text some text some text some text} \\
\end{longtable}


\begin{longtable}{@{}wr{\firstcolwidth}|p{\combinedcolwidth}@{}}
2017 -- 2019 &\textbf{Company 1} \\
             & \begin{tabular}{@{}wr{\secondcolwidth}p{\thirdcolwidth}@{}}
                About:   & some text some text some text some text some text \\
                Role:    & some text some text some text  some text some text some text some text some text some text some text some text some text some text some text some text \\
               Contact: & some text \\
               Email:   & some text \\
               \end{tabular}\\
\multicolumn{2}{l}{}\\
2015         & \textbf{Company 2} \\
             & some text some text some text some text some text some text some text some text some text some text some text some text \\
             & some text some text some text some text \\
\end{longtable}

\end{document}

相关内容