自定义部分标题看起来不相似(尽管具有相同的代码)

自定义部分标题看起来不相似(尽管具有相同的代码)

我制作了以下自定义部分标题:

在此处输入图片描述

这里有相当多的东西是硬编码的(即需要我亲眼观察),这让我很紧张。

  1. 为什么两者的vrules宽度不一样(它们都有厚度)?如果我改为,3pt这个问题就消失了,但我不知道为什么会发生这种情况。\titlespacing\section{6.8in}{0in}{0in}\titlespacing\section{6.0in}{0in}{0in}
  2. 如何确保右对齐标题与页边距齐平?现在,可以使用值6.67in(A4 纸宽度 - 左边距宽度 - 右边距宽度 = 8.27 - 0.8 - 0.8 = 6.67) 手动完成,但由于某种原因,右侧的空间看起来比左侧的大。
  3. 如何确保vrule和文本之间的间距相似?现在,它是使用手动完成的\hspace,我确信它们是不一样的。

我真的很感谢所有的意见——手动做事让我非常焦躁。


以上内容为:

% these define the type of document and the look of the page
\documentclass[]{article}
\usepackage{lmodern}
\usepackage[toc,page]{appendix}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\usepackage[margin=0.8in, top = 1.3in, headheight = 0.6in]{geometry}
%\usepackage[bottom, flushmargin]{footmisc}
\setlength{\footnotesep}{\baselineskip} % space between footnotes 
\setlength{\parindent}{0pt} % space at start of paragraph
\setlength{\parskip}{0.14in} % space between paragraphs
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}

% colors
\usepackage{tcolorbox}
\usepackage{color} % colors
\usepackage{xcolor, colortbl} % more control over colors
\definecolor{c1}{HTML}{122084}

% heading formats
\usepackage[explicit]{titlesec}
\titlespacing\subsection{0pt}{0.21in}{0.01in}
\titlespacing\subsubsection{0pt}{0.21in}{0in}


% table-related
\usepackage{array}
\usepackage{booktabs}
\usepackage{multicol, makecell}
\usepackage{multirow, hhline}
\usepackage{siunitx}
\newcommand\bstrut{\rule{0pt}{2.5ex}} % space before row
\newcommand\astrut{\rule[-1.25ex]{0pt}{0pt}} % space after row
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}


\begin{document}

\thispagestyle{plain}

\newcommand{\hsp}{\hspace{-10.7cm}}
\titlespacing\section{6.67in}{0in}{0in}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{\color{c1}}{20pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt}>{\hsp}r}#1\end{tabular}}

\section*{An Internationally \\ Renowned Title}

\vspace{0.5in}

\renewcommand{\hsp}{\hspace{20pt}}
\titlespacing\section{0cm}{0in}{0in}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{\color{c1}}{20pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt}>{\hsp}l}#1\end{tabular}}

\section*{An Internationally \\ Renowned Title}

\end{document}

答案1

在软件包 (\filleft, \filrightfilcenter) 提供的对齐工具中使用相关工具更为有效。我借此机会稍微简化了您的代码 -color如果您要加载,则无需加载xcolor,而使用选项加载后者[table]将使您不必加载colortbl(在这种情况下,在之后加载tcolorbox,以避免选项冲突)。

% these define the type of document and the look of the page
\documentclass[a4paper]{article}
\usepackage{lmodern}
\usepackage[toc,page]{appendix}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\usepackage[margin=0.8in, top=1.3in, headheight=0.6in, showframe]{geometry}
%\usepackage[bottom, flushmargin]{footmisc}
\setlength{\footnotesep}{\baselineskip} % space between footnotes
\setlength{\parindent}{0pt} % space at start of paragraph
\setlength{\parskip}{0.14in} % space between paragraphs
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}

% colors
\usepackage[table]{xcolor} % more control over colors
\definecolor{c1}{HTML}{122084}
\usepackage{tcolorbox}

% heading formats
\usepackage[explicit]{titlesec}
\titlespacing\subsection{0pt}{0.21in}{0.01in}
\titlespacing\subsubsection{0pt}{0.21in}{0in}


% table-related
\usepackage{array}
\usepackage{booktabs}
\usepackage{multicol, makecell}
\usepackage{multirow, hhline}
\usepackage{siunitx}
\newcommand\bstrut{\rule{0pt}{2.5ex}} % space before row
\newcommand\astrut{\rule[-1.25ex]{0pt}{0pt}} % space after row
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\thispagestyle{plain}

\newcommand{\hsp}{\hspace{20pt}}
\titlespacing\section{0in}{0in}{0in}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries\filleft}{}{0pt}{\begin{tabular}[t]{r@{\hsp\color{c1}\vrule width 3pt}}#1\end{tabular}}

\section*{An Internationally \\ Renowned Title}

\vspace{0.5in}

\titlespacing\section{0cm}{0in}{0in}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{}{0pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt\hsp}l}#1\end{tabular}}

\section*{An Internationally \\ Renowned Title}

\end{document} 

在此处输入图片描述

相关内容