我想为我的表格创建一条垂直线或列线,它只能为表头和第一列创建垂直线,但不能为其余列的主体创建垂直线。
这是我的代码:
\begin{table}[h]
\begin{center}
\begin{tabular}{c | c | c | c | c }
\hline
\multicolumn{1}{c|}{$p$} & \multicolumn{1}{c|}{$q$} & \multicolumn{1}{c|}{$p \land q$} & \multicolumn{1}{c|}{$p \lor q$} & \multicolumn{1}{c|}{$p \oplus q$} \\
\hline
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T }}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
\\
\\
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
\\
\\
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{T}}}}
\\
\\
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
& \multicolumn{1}{c}
{\multirow{1}{*}
{{\parbox[t]{0.4cm}{F}}}}
\end{tabular}
\caption{The truth table for the Conjunction, Disjunction and Exclusive or}
\end{center}
\end{table}
答案1
- 我不确定您在寻找什么,但我怀疑您可能在寻找以下内容:
\documentclass[parsk multirowip=half-]{scrreprt}
\usepackage{makecell}
\begin{document}
\begin{table}[h]
\setcellgapes{3pt}
\makegapedcells
\centering
\begin{tabular}{| c | c | c | c | c |}
\hline
$p$ & $q$ & $p\land q$ & $p\lor q$ & $p \oplus q$ \\ \hline
T & T & T & T & F \\
T & F & F & T & T \\
F & T & F & T & T \\
F & F & F & F & F
\end{tabular}
\caption{The truth table for the Conjunction, Disjunction and Exclusive or}
\end{table}
\end{document}
- 正如问题下方的评论中提到的,您的大多数代码都没有执行任何操作,即只是一片混乱。我删除了它们。
编辑:tabularray
通过使用包来编写表格, 可以得到更简单、更简短的表格代码:
\documentclass[parsk multirowip=half-]{scrreprt}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\centering
\begin{tblr}{hline{1,2,Z}, vlines,
colspec = {*{5}{Q[c, wd=2em]}},
rowsep = 3pt,
row{1} = {mode=math}
}
p & q & p\land q & p\lor q & p\oplus q \\
T & T & T & T & F \\
T & F & F & T & T \\
F & T & F & T & T \\
F & F & F & F & F \\
\end{tblr}
\caption{The truth table for the Conjunction, Disjunction and Exclusive or}
\end{table}
\end{document}
答案2
列规范中两列之间的横线|
在表格中添加一条垂直线
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{*2{wc{0.45cm}} | *3{wc{0.75cm}}}
\hline
\(p\) & \(q\) & \(p\land q\) & \(p\lor q\) & \(p \oplus q\) \\
\hline
T & T & T & T & F \\
T & F & F & T & T \\
F & T & F & T & T \\
F & F & F & F & F \\
\hline
\end{tabular}
\caption{The truth table for the Conjunction, Disjunction and Exclusive or}
\label{tab:table1}
\end{table}
\end{document}
例如,改变这一行
\begin{tabular}{*2{wc{0.45cm}} | *3{wc{0.75cm}}}
到
\begin{tabular}{| *5{wc{0.75cm}|}}
在各处添加垂直线。此表达式缩短*5{wc{0.75cm}|}
了array
许多相同列的定义。
如果你选择更好的演示,书签是一个推荐的软件包,它有额外的规则和间距。但是,它不能很好地处理垂直线留下的小间隙。补救措施是使用\specialrule
以便从规则中删除额外的间距,然后使用 struts 将其添加回来。请参阅下面的解决方案。宏不是必需的,但有助于使表格的主要代码更整洁
\documentclass{article}
\usepackage{array}
\usepackage{booktabs} % for rule alternatives,
\begin{document}
\begin{table}[tbh]
%%% Local definitions to reduce clutters
% can also be in the preamble for global scope
\newcommand{\ustrut}{\rule{0pt}{11pt}}
\newcommand{\lstrut}{\rule[-7pt]{0pt}{7pt}}
\NewExpandableDocumentCommand{\hzrule}{}{% requires booktabs
\specialrule{\heavyrulewidth}{0pt}{0pt}}
\NewExpandableDocumentCommand{\lzrule}{}{% requires booktabs
\specialrule{\lightrulewidth}{0pt}{0pt}}
%%% END of Local Definitions
\centering
\renewcommand{\arraystretch}{1.1}
\begin{tabular}{
*2{wc{0.45cm}} % column spec.
| @{\hspace{0.85em}} % v. bar + extra spacing between 2 columns
*3{wc{0.75cm}} % column spec.
}
\hzrule
\(p\) & \(q\) & \(p\land q\) & \(p\lor q\) & \(p \oplus q\) \lstrut \\
\lzrule
T & T & T & T & F \ustrut \\
T & F & F & T & T \\
F & T & F & T & T \\
F & F & F & F & F \\
\hzrule
\end{tabular}
\caption{The truth table for the Conjunction, Disjunction and Exclusive or}
\label{tab:table2}
\end{table}
\end{document}