longtable
我正在尝试使用hhline
和在某些单元格周围放置一些粗体和彩色边框 multicolumn
。我注意到,\setlength\arrayrulewidth
如果行是-
或=
和 ,则行为会有所不同,我希望有人可以解释原因。
完整代码:
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{caption}[singlelinecheck=off]
\usepackage{longtable}
\setlength{\LTleft}{0pt plus 1fill minus 1fill}
\setlength{\LTright}{\LTleft}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{color}
\usepackage{colortbl, hhline}
\usepackage{array}
\usepackage{threeparttablex}
\def\settotextwidth{\renewcommand\TPTminimum{\textwidth}}
\begin{document}
\definecolor{purple}{rgb}{0.694117647058824,0.611764705882353,0.850980392156863}
\newcommand{\boldcolored}{\arrayrulecolor{purple}\setlength\arrayrulewidth{5pt}}
\newcommand{\regcolored}{\arrayrulecolor{purple}}
\newcommand{\resetcolor}{\arrayrulecolor{black}}
\newcommand{\vboldcolored}{{\color{purple}\vline width 5pt}}
\begin{ThreePartTable}
\settotextwidth
\begin{TableNotes}
\setlength\labelsep{0pt}
\footnotesize
\arraybackslash\raggedright
\item
\arraybackslash\raggedright
\item Script code:
\item Tex code:
\end{TableNotes}
\begin{center}
\setlength\labelsep{0pt}
{\large Fruit Table } \\
\vspace{3mm}
{\small testing } \\
\vspace{-3mm}
\end{center}
\setlength{\tabcolsep}{3pt}
\captionsetup[table]{labelformat=empty,skip=3pt, justification=raggedright, width =\textwidth}
\begin{longtable}{p{1.72cm}p{1.72cm}p{1.72cm}p{1.72cm}}
\toprule
& & \multicolumn{2}{c}{Summary} \\
\cmidrule(lr){3-4}
Category & Fruit & Total & Color\\
\endfirsthead
\endhead
\bottomrule
\addlinespace
\insertTableNotes
\endlastfoot
\midrule
\multicolumn{4}{l}{Least Favorite} \\
\midrule
\multicolumn{1}{!\vboldcolored l !\vboldcolored}{fruit 3}& grape & \multicolumn{1}{!\vboldcolored l !\vboldcolored}{3} & purple \\
\hhline{>{\boldcolored}=>{\regcolored}=>{\boldcolored}->{\regcolored}-}\resetcolor
fruit 4 & pear & 4 & green \\
fruit 5 & orange & 5 & orange \\
\midrule
Total & — & 12 & — \\
AVG & — & 4 & — \\
\midrule
\multicolumn{4}{l}{\vspace*{-5mm}} \\
\midrule
fruit 1 & apple & 1 & red \\
fruit 2 & banana & 2 & yellow \\
\midrule
Sum ALL & — & 15 & — \\
\bottomrule
\end{longtable}
\end{ThreePartTable}
\end{document}
使用pdflatex
我的表格输出为:
我不明白为什么该\boldcolored
命令似乎只对=
这里的行有效,而对那一行无效-
?
为了检查这是否是更改规则宽度中线的问题,我将切换-
到第一个位置并尝试将其加粗,但没有成功。我还将粗线移到=
中线,这样我就可以更改规则宽度了。输出:
第二张表的代码:
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{caption}[singlelinecheck=off]
\usepackage{longtable}
\setlength{\LTleft}{0pt plus 1fill minus 1fill}
\setlength{\LTright}{\LTleft}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{color}
\usepackage{colortbl, hhline}
\usepackage{array}
\usepackage{threeparttablex}
\def\settotextwidth{\renewcommand\TPTminimum{\textwidth}}
\begin{document}
\definecolor{purple}{rgb}{0.694117647058824,0.611764705882353,0.850980392156863}
\newcommand{\boldcolored}{\arrayrulecolor{purple}\setlength\arrayrulewidth{5pt}}
\newcommand{\regcolored}{\arrayrulecolor{purple}}
\newcommand{\resetcolor}{\arrayrulecolor{black}}
\newcommand{\vboldcolored}{{\color{purple}\vline width 5pt}}
\begin{ThreePartTable}
\settotextwidth
\begin{TableNotes}
\setlength\labelsep{0pt}
\footnotesize
\arraybackslash\raggedright
\item
\arraybackslash\raggedright
\item Script code:
\item Tex code:
\end{TableNotes}
\begin{center}
\setlength\labelsep{0pt}
{\large Fruit Table } \\
\vspace{3mm}
{\small testing } \\
\vspace{-3mm}
\end{center}
\setlength{\tabcolsep}{3pt}
\captionsetup[table]{labelformat=empty,skip=3pt, justification=raggedright, width =\textwidth}
\begin{longtable}{p{1.72cm}p{1.72cm}p{1.72cm}p{1.72cm}}
\toprule
& & \multicolumn{2}{c}{Summary} \\
\cmidrule(lr){3-4}
Category & Fruit & Total & Color\\
\endfirsthead
\endhead
\bottomrule
\addlinespace
\insertTableNotes
\endlastfoot
\midrule
\multicolumn{4}{l}{Least Favorite} \\
\midrule
\multicolumn{1}{!\vboldcolored l !\vboldcolored}{fruit 3}& grape & \multicolumn{1}{!\vboldcolored l !\vboldcolored}{3} & purple \\
\hhline{>{\boldcolored}->{\regcolored}=>{\boldcolored}=>{\regcolored}-}\resetcolor
fruit 4 & pear & 4 & green \\
fruit 5 & orange & 5 & orange \\
\midrule
Total & — & 12 & — \\
AVG & — & 4 & — \\
\midrule
\multicolumn{4}{l}{\vspace*{-5mm}} \\
\midrule
fruit 1 & apple & 1 & red \\
fruit 2 & banana & 2 & yellow \\
\midrule
Sum ALL & — & 15 & — \\
\bottomrule
\end{longtable}
\end{ThreePartTable}
\end{document}
答案1
@DavidCarlisle 对这种行为进行了解释,帮助我找到了我正在寻找的解决方案,因此将其作为答案发布以结束此问题。
区别在于,本质上 - 只是一条规则,但 = 必须用 \leaders 来制作,其中包含一个带有两条规则的框,并且该框只需制作一次
看着hhline
:
\HH@box
创建构成双线段的框。
\def\HH@box#1#2{\vbox{%
\hrule \@height \arrayrulewidth \@width #1
\vskip \doublerulesep
\hrule \@height \arrayrulewidth \@width #2}}
该盒子由两条规则和一条规则分隔符组成。单线只是\hrule
。
因此,使用此信息,只需使用以下方法即可在特定单元格周围制作厚/彩色框边框hhline
:
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{caption}[singlelinecheck=off]
\usepackage{longtable}
\setlength{\LTleft}{0pt plus 1fill minus 1fill}
\setlength{\LTright}{\LTleft}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{color}
\usepackage{colortbl, hhline}
\usepackage{array}
\usepackage{threeparttablex}
\def\settotextwidth{\renewcommand\TPTminimum{\textwidth}}
\begin{document}
\definecolor{purple}{rgb}{0.694117647058824,0.611764705882353,0.850980392156863}
\begin{ThreePartTable}
\newcommand{\borderheight}{\dimexpr 2.495pt + \ht\strutbox}
\newcommand{\boldcolored}{\arrayrulecolor{purple}\setlength\arrayrulewidth{2.495pt}\setlength\doublerulesep{0.01pt}}
\newcommand{\vboldcolored}{{\color{purple}\vline width 5pt height \borderheight}}
\newcommand{\resetcolor}{\arrayrulecolor{black}}
\settotextwidth
\begin{TableNotes}
\setlength\labelsep{0pt}
\footnotesize
\arraybackslash\raggedright
\item
\arraybackslash\raggedright
\item Script code:
\item Tex code:
\end{TableNotes}
\begin{center}
\setlength\labelsep{0pt}
{\large Fruit Table } \\
\vspace{3mm}
{\small testing } \\
\vspace{-3mm}
\end{center}
\setlength{\tabcolsep}{3pt}
\captionsetup[table]{labelformat=empty,skip=3pt, justification=raggedright, width =\textwidth}
\begin{longtable}{p{1.72cm}p{1.72cm}p{1.72cm}p{1.72cm}}
\toprule
& & \multicolumn{2}{c}{Summary} \\
\cmidrule(lr){3-4}
Category & Fruit & Total & Color\\
\endfirsthead
\endhead
\bottomrule
\addlinespace
\insertTableNotes
\endlastfoot
\midrule
\multicolumn{4}{l}{Least Favorite} \\
\midrule
\hhline{>{\boldcolored}=>{\boldcolored}=~~}\resetcolor
\multicolumn{1}{!\vboldcolored l}{fruit 3}& \multicolumn{1}{l !\vboldcolored}{grape} & 3 & purple \\
\hhline{>{\boldcolored}=>{\boldcolored}=~~}\resetcolor
fruit 4 & pear & 4 & green \\
fruit 5 & orange & 5 & orange \\
\midrule
Total & — & 12 & — \\
AVG & — & 4 & — \\
\midrule
\multicolumn{4}{l}{\vspace*{-5mm}} \\
\midrule
fruit 1 & apple & 1 & red \\
fruit 2 & banana & 2 & yellow \\
\midrule
Sum ALL & — & 15 & — \\
\bottomrule
\end{longtable}
\end{ThreePartTable}
\end{document}
将设置\doublerulesep
为接近零(.01 - 设置为零不起作用),以便线条合在一起为 1。我最初想要一条 5pt 粗线,所以我将arrayrulewidth
每条设置为 0.5x5pt-(0.5x(0.01)) = 2.495pt,这样当它们合在一起时它们就是 5pt。这个输出就是我想要的,而且比我看到的一些用于特定单元格周围彩色框的解决方案要容易得多tikz
。