我有一个如下的分隔符:
\documentclass[a4paper,11pt]{article}
\usepackage{xcolor}
\usepackage{titlesec}
\definecolor{pink}{HTML}{F8CBAD}
\definecolor{grey}{HTML}{D9D9D9}
\titleformat{\section}{
\vspace{-4pt}\scshape\raggedright\large
}{}{0em}{}[\vspace{-5pt}\color{pink}\rule{5cm}{0.7mm} \color{grey}\rule{13.3cm}{0.7mm}]
\begin{document}
\section{Research Interests}
...
\section{Selected Courses and Grades}
\end{document}
我需要的?
我想将粉红线的长度指定为其上方的文本的长度,来自titleformat
。灰线占据了该线的其余部分。
答案1
您可以测量文本并使用此长度。唯一的问题是此设置应该是全局的。
\documentclass[a4paper,11pt]{article}
\usepackage{xcolor}
\usepackage{titlesec}
\definecolor{pink}{HTML}{F8CBAD}
\definecolor{grey}{HTML}{D9D9D9}
\titleformat{\section}
{\large\scshape\filright}
{}
{0em}
{\makesectiontitle}
[%
\vspace{-5pt}%
\color{pink}\rule{\sectiontitlewd}{0.7mm}\hspace{0.33333em}%
\color{grey}\rule{\dimexpr\textwidth-\sectiontitlewd-0.33333em}{0.7mm}%
]
\newlength{\sectiontitlewd}
\newcommand{\makesectiontitle}[1]{%
\settowidth{\dimen0}{#1}%
\global\sectiontitlewd=\dimen0
#1%
}
\begin{document}
\section{Research Interests}
...
\section{Selected Courses and Grades}
\end{document}
答案2
以下是使用calcwidth
titlesec 选项的解决方案:
\documentclass[a4paper,11pt]{article}
\usepackage{xcolor}
\usepackage[calcwidth]{titlesec}
\definecolor{pink}{HTML}{F8CBAD}
\definecolor{grey}{HTML}{D9D9D9}
\titleformat{\section}{\scshape\raggedright\large}{}{0em}{}%
[\color{pink}{\rule[7pt]{\titlewidth}{0.7mm}}\color{grey}{\rule[7pt]{\dimexpr\textwidth-\titlewidth}{0.7mm}}]
\begin{document}
\section{Research Interests}
The Clangle-Wangle
\section{Selected Courses and Grades}
\end{document}
答案3
\documentclass[a4paper,11pt]{article}
\usepackage{xcolor}
\usepackage{titlesec}
\definecolor{pink}{HTML}{F8CBAD}
\definecolor{grey}{HTML}{D9D9D9}
\titleformat{\section}{
\vspace{-4pt}\scshape\raggedright\large
}{}{0em}{}[\vspace{-5pt}\color{pink}\rule{\wd8}{0.7mm}\color{grey}%
\rule{\dimexpr\linewidth-\wd8}{0.7mm}]
\let\svsection\section
\renewcommand\section[2][\relax]{%
\sbox8{\large\textsc{#2}}%
\ifx\relax#1\def\next{\svsection}%
\else\def\next{\svsection[#1]}%
\fi\next{#2}%
}
\begin{document}
\section{Research Interests}
...
\section{Selected Courses and Grades}
\end{document}