我有一张包含 3 列的简单表格,我将其用作数据标题。我定义了自定义下划线规则(具有自定义粗细、颜色和深度),并使用该规则为每个表格条目添加下划线。
我使用的标记是:
\documentclass[letterpaper,11pt]{article}
\usepackage{kpfonts}
\RequirePackage{fix-cm}
\setlength{\parskip}{\baselineskip}%
\setlength{\parindent}{0pt}%
\usepackage{xcolor}
\definecolor{smokyblack}{rgb}{0.06, 0.05, 0.03}
\definecolor{mygrey}{rgb}{0.1, 0.14, 0.12}
\definecolor{darkjunglegreen}{rgb}{0.0, 0.26, 0.15}
\usepackage[
top = 0.608cm,
bottom = 1.1cm,
left = 1.20cm,
right = 1.10cm]{geometry}
\usepackage{titlesec}
\usepackage{ulem}
\renewcommand{\ULdepth}{5.8pt}
\renewcommand{\ULthickness}{1.35pt}
\makeatletter
\newcommand\semiLarge{\@setfontsize\semiLarge{13.22}{17.38}}
\makeatother
\newcommand{\greenuline}[1]{{\color{darkjunglegreen}\uline{{\color{black}#1}}}}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}
{1em}{}[\color{darkjunglegreen}{\titlerule[2pt]}]
\titlespacing\section{0pt}{1pt plus 4pt minus 2pt}{-3pt plus 2pt minus 2pt}
\begin{document}
\sloppy
\begin{tabular*}{\linewidth}{@{}l@{\extracolsep{\fill}}r@{}}
\textbf{\LARGE \textcolor{mygrey}{REAL NAME}} & \large{[email protected]}\\
\colorbox{mygrey!11}{\textbf{\semiLarge \textcolor{smokyblack}{Employed Professional}}} & \large{555-555-5555 - New York, NY}
\end{tabular*}
\section*{Section Heading}
\begin{tabular} {@{}p{6cm} p{8cm} p{7cm}}
\large{\textbf{\greenuline{Category}}} & \large{\textbf{\greenuline{Word}}} & \large{\textbf{\greenuline{Much Longer word}}}
\end{tabular}
\end{document}
它产生如下输出:
目前一切都按预期进行。我想将每个表格条目置于列的中心,并让我的下划线规则填充表格列的宽度,如下图所示:
这个问题最简单的解决办法是什么?
答案1
借助\cmidrule
包booktabs
和tabular*
确保表格保持在文本宽度内。可以使用可选参数控制线条粗细\cmidrule
。
\documentclass[letterpaper,11pt]{article}
\usepackage{kpfonts}
\RequirePackage{fix-cm}
\setlength{\parskip}{\baselineskip}%
\setlength{\parindent}{0pt}%
\usepackage[table]{xcolor}
\definecolor{smokyblack}{rgb}{0.06, 0.05, 0.03}
\definecolor{mygrey}{rgb}{0.1, 0.14, 0.12}
\definecolor{darkjunglegreen}{rgb}{0.0, 0.26, 0.15}
\usepackage[
top = 0.608cm,
bottom = 1.1cm,
left = 1.20cm,
right = 1.10cm]{geometry}
\usepackage{titlesec}
\usepackage{ulem}
\renewcommand{\ULdepth}{5.8pt}
\renewcommand{\ULthickness}{1.35pt}
\makeatletter
\newcommand\semiLarge{\@setfontsize\semiLarge{13.22}{17.38}}
\makeatother
\newcommand{\greenuline}[1]{{\color{darkjunglegreen}\uline{{\color{black}#1}}}}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}
{1em}{}[\color{darkjunglegreen}{\titlerule[2pt]}]
\titlespacing\section{0pt}{1pt plus 4pt minus 2pt}{-3pt plus 2pt minus 2pt}
\usepackage{booktabs}
\usepackage{array}
\usepackage{calc}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\sloppy
\begin{tabular*}{\linewidth}{@{}l@{\extracolsep{\fill}}r@{}}
\textbf{\LARGE \textcolor{mygrey}{REAL NAME}} & \large{[email protected]}\\
\colorbox{mygrey!11}{\textbf{\semiLarge \textcolor{smokyblack}{Employed Professional}}} & \large{555-555-5555 - New York, NY}
\end{tabular*}
\section*{Section Heading}
\arrayrulecolor{darkjunglegreen}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{3}{C{0.3\textwidth-2\tabcolsep}}}
\large\textbf{Category} & \large\textbf{Word} & \large\textbf{Much Longer word}\\
\cmidrule[1pt](r){1-1} \cmidrule[1pt](lr){2-2} \cmidrule[1pt](l){3-3}
\end{tabular*}
\end{document}
答案2
除了使用 p 列之外,还可以使用 设置宽度\makebox
。
BTW<\large
没有参数。它是一个开关,应该放在括号内。
\documentclass[letterpaper,11pt]{article}
\usepackage{kpfonts}
\RequirePackage{fix-cm}
\setlength{\parskip}{\baselineskip}%
\setlength{\parindent}{0pt}%
\usepackage{xcolor}
\definecolor{smokyblack}{rgb}{0.06, 0.05, 0.03}
\definecolor{mygrey}{rgb}{0.1, 0.14, 0.12}
\definecolor{darkjunglegreen}{rgb}{0.0, 0.26, 0.15}
\usepackage[
top = 0.608cm,
bottom = 1.1cm,
left = 1.20cm,
right = 1.10cm]{geometry}
\usepackage{titlesec}
\usepackage{ulem}
\renewcommand{\ULdepth}{5.8pt}
\renewcommand{\ULthickness}{1.35pt}
\makeatletter
\newcommand\semiLarge{\@setfontsize\semiLarge{13.22}{17.38}}
\makeatother
\newcommand{\greenuline}[1]{{\color{darkjunglegreen}\uline{{\color{black}#1}}}}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}
{1em}{}[\color{darkjunglegreen}{\titlerule[2pt]}]
\titlespacing\section{0pt}{1pt plus 4pt minus 2pt}{-3pt plus 2pt minus 2pt}
\begin{document}
\sloppy
\begin{tabular*}{\linewidth}{@{}l@{\extracolsep{\fill}}r@{}}
\textbf{\LARGE \textcolor{mygrey}{REAL NAME}} & \large{[email protected]}\\
\colorbox{mygrey!11}{\textbf{\semiLarge \textcolor{smokyblack}{Employed Professional}}} & \large{555-555-5555 - New York, NY}
\end{tabular*}
\section*{Section Heading}
\begin{tabular*}{\textwidth} {@{\extracolsep{\fill}}lll@{}}
\textbf{\large\greenuline{\makebox[6cm]{Category}}} & \textbf{\large\greenuline{\makebox[6cm]{Word}}}
& \textbf{\large\greenuline{\makebox[6cm]{Much Longer word}}}
\end{tabular*}
\end{document}