
製作時tabularx
需要給予一個桌子寬度。對於最外面的表,可以使用\textwidth
.
當在外表內建立一個或多個內表時,內表還需要一個寬度,在這種情況下,該寬度就是該內表所在的外表列的寬度很難追蹤上下文並手動給出硬編碼值。
我無法弄清楚如何告訴 LaTeX 使用外部表中所有可用的列寬度,並讓 LaTeX 進行計算。需要類似X
表寬度本身的東西。
這是一張 MWE,一張桌子放在另一張桌子上。
\documentclass[10pt,notitlepage]{article}%
\usepackage{tabularx}
\usepackage{hyperref}
\usepackage{array}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
%have to use tabular* for outer table since I can't figure how to use tabularx
\begin{tabular*}{\textwidth}{|p{0.5\textwidth}|p{0.5\textwidth}|}\hline
\begin{tabularx}{0.5\textwidth}{@{}|Y|Y|Y|@{}}\hline % how to automate this?
% instead of 0.5\textwidth
% use full column width
\href{foo/index.htm}{A}
\begin{enumerate}
\item item 1
\item item 2
\end{enumerate}&
\href{foo/index.htm}{B}&
\href{foo/index.htm}{C}\\\hline
\end{tabularx}
&
second column
\end{tabular*}
\end{document}
答案1
您可以使用\linewidth
。有用的參考是:這個 Q 和它的 A。最好用於p{\dimexpr0.5\textwidth-2\tabcolsep\relax}
外部表格和左對齊的單元格結構enumerate
。
\documentclass[10pt,notitlepage]{article}%
\usepackage{tabularx}
\usepackage{hyperref}
\usepackage{array}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
%have to use tabular* for outer table since I can't figure how to use tabularx
\noindent\begin{tabular*}{\textwidth}{|p{\dimexpr0.5\textwidth-2\tabcolsep\relax}|
@{\extracolsep{\fill}}p{\dimexpr0.5\textwidth-2\tabcolsep\relax}|}\hline
\begin{tabularx}{\linewidth}{@{}|p{0.35\hsize}|Y|Y|@{}}\hline % how to automate this?
% instead of 0.5\textwidth
% use full column width
{\centering \href{foo/index.htm}{A}\par}
\begin{enumerate}
\item item 1
\item item 2
\end{enumerate}
&
\href{foo/index.htm}{B}&
\href{foo/index.htm}{C}\\\hline
\end{tabularx}
&
second column
\end{tabular*}
\end{document}
答案2
看看這是否是您想要實現的目標:
\documentclass[10pt,notitlepage]{article}%
\usepackage{array,tabularx,hyperref}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\begin{tabularx}{\textwidth}{|@{}X@{}|X|}%outer table, @{} omit column separation
\hline
{\begin{tabularx}{\hsize}{|Y|Y|Y|}
\hline
\href{foo/index.htm}{A}
\begin{enumerate}
\item item 1
\item item 2
\end{enumerate} &
\href{foo/index.htm}{B} &
\href{foo/index.htm}{C} \\
\hline
\end{tabularx}}
& second column \\
\end{tabularx}
\end{document}