Latex 多行表格文本和边框混乱

Latex 多行表格文本和边框混乱

我有下表(下面的代码):

\documentclass[a4paper,fleqn]{cas-sc}

%\usepackage[numbers]{natbib}
%\usepackage[authoryear]{natbib}
\usepackage[authoryear,longnamesfirst]{natbib}
\usepackage{chemformula}
\usepackage{booktabs}
\usepackage{multirow}

\begin{table}[width=.9\linewidth,cols=6,pos=h]
\caption{Description of nodes in the Dynamic Bayesian Network shown in Fig \ref{FIG:dbn}}\label{tab:dbntable}
\begin{tabular*}{\tblwidth}{@{} |l|l|p{0.05\textwidth}|p{0.1\textwidth}|p{0.15\textwidth}|p{0.3\textwidth}|@{} }
\toprule
Node name &
  Type &
  Time-steps &
  Conditional   dependcy &
  States &
  Description \\ \midrule
Prior &
  \multirow{6}{*}{Initial} &
  \multirow{6}{*}{t=0} &
  None &
  11 states indicating   score in the range {[}0-10{]} &
  A state of 0 denotes   a student who scored a 0 in the pre-test while a state of 10 represents a   student who scored 100\% in the pre-test \\ \cmidrule(r){1-1} \cmidrule(l){4-6} 
Knowledge0 &
   &
   &
  Prior &
  \multirow{10}{*}{True and False} &
  State of true denotes   the possibility that the student has the required knowledge at timestep t=0 \\ \cmidrule(r){1-1} \cmidrule(lr){4-4} \cmidrule(l){6-6} 
Distractor00 &
   &
   &
  \multirow{5}{*}{Knowledge0} &
   &
  \multirow{3}{*}{True denotes the evidence   that the student has collected this distractor at timestep t=0} \\ \cmidrule(r){1-1}
Distractor01 &
   &
   &
   &
   &
   \\ \cmidrule(r){1-1}
Distractor02 &
   &
   &
   &
   &
   \\ \cmidrule(r){1-1} \cmidrule(l){6-6} 
Question0 &
   &
   &
   &
   &
  True denotes the   evidence that the student answered the quiz correctly at timestep t=0 \\ \cmidrule(r){1-3} \cmidrule(l){6-6} 
Knowledge1 &
  \multirow{5}{*}{Temporal} &
  \multirow{5}{*}{t=1,2,3} &
   &
   &
  True denotes the   possibility that the student has the required knowledge at timestep t=1,2,3 \\ \cmidrule(r){1-1} \cmidrule(lr){4-4} \cmidrule(l){6-6} 
Distractor10 &
   &
   &
  \multirow{4}{*}{Knowledge1} &
   &
  \multirow{3}{*}{True denotes the evidence   that the student has collected this distractor at timestep t=1,2,3} \\ \cmidrule(r){1-1}
Distractor11 &
   &
   &
   &
   &
   \\ \cmidrule(r){1-1}
Distractor12 &
   &
   &
   &
   &
   \\ \cmidrule(r){1-1} \cmidrule(l){6-6} 
Question1 &
   &
   &
   &
   &
  True denotes the   evidence that the student answered the quiz correctly at timestep t=1,2,3 \\
\bottomrule
\end{tabular*}
\end{table}

表格看起来乱糟糟的,边框奇怪,文字超出页面范围。我该如何修复? 在此处输入图片描述

答案1

正如我在评论中提到的,来自包和垂直线的规则并没有给出很好的结果,因为在规则周围添加了一些垂直空间并且如果您需要的话缩短了它们(就像booktabs您在表格中所做的那样)使用(l)或选项。(r)(lr)\cmidrule

看看,如果解决方案使用了makacell包(用于\Xhline单元格中的附加垂直空间),tabularx(用于正确的跨度表宽度)amd\multirow{...}{=}{...}语法会得到您想要的结果:

\documentclass[a4paper,fleqn]{cas-sc}

%\usepackage[numbers]{natbib}
%\usepackage[authoryear]{natbib}
\usepackage[authoryear,longnamesfirst]{natbib}
\usepackage{chemformula}
\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}[width=\linewidth,cols=6,pos=h]
    \setcellgapes{3pt}
    \makegapedcells    
\caption{Description of nodes in the Dynamic Bayesian Network shown in Fig \ref{FIG:dbn}}\label{tab:dbntable}
\begin{tabularx}{\tblwidth}{|L|L|
                            >{\hsize=0.8\hsize}L|
                            L|
                            >{\hsize=1.2\hsize}L|
                            p{0.35\textwidth}|
                            }
    \Xhline{1.2pt}
Node name &
  Type &
  Time-steps &
  Conditional   dependcy &
  States &
  Description \\ 
    \Xhline{0.6pt}
Prior &
  \multirow{6}{=}{Initial} &
  \multirow{6}{=}{t=0} &
  None &
  11 states indicating   score in the range {[}0-10{]} &
  A state of 0 denotes   a student who scored a 0 in the pre-test while a state of 10 represents a   student who scored 100\% in the pre-test \\ \cline{1-1} \cline{4-6}
Knowledge0 &
   &
   &
  Prior &
  \multirow{10}{=}{True and False} &
  State of true denotes   the possibility that the student has the required knowledge at timestep t=0 \\ \cline{1-1} \cline{4-4} \cline{6-6}
Distractor00 &
   &
   &
  \multirow{5}{=}{Knowledge0} &
   &
  \multirow{3}{=}{True denotes the evidence   that the student has collected this distractor at timestep t=0} \\ \cline{1-1}
Distractor01 &
   &
   &
   &
   &
   \\ \cline{1-1}
Distractor02 &
   &
   &
   &
   &
   \\ \cline{1-1} \cline{6-6}
Question0 &
   &
   &
   &
   &
  True denotes the   evidence that the student answered the quiz correctly at timestep t=0 \\ \cline{1-3} \cline{6-6}
Knowledge1 &
  \multirow{5}{=}{Temporal} &
  \multirow{5}{=}{t=1,2,3} &
   &
   &
  True denotes the   possibility that the student has the required knowledge at timestep t=1,2,3 \\ \cline{1-1} \cline{4-4} \cline{6-6}
Distractor10 &
   &
   &
  \multirow{4}{=}{Knowledge1} &
   &
  \multirow{3}{=}{True denotes the evidence   that the student has collected this distractor at timestep t=1,2,3} \\ \cline{1-1}
Distractor11 &
   &
   &
   &
   &
   \\ \cline{1-1}
Distractor12 &
   &
   &
   &
   &
   \\ \cline{1-1} \cline{6-6}
Question1 &
   &
   &
   &
   &
  True denotes the   evidence that the student answered the quiz correctly at timestep t=1,2,3 \\
    \Xhline{1.2pt}
\end{tabularx}
    \end{table}
\end{document}

在此处输入图片描述

(红线显示页面布局)

相关内容