将章节标题和副标题与两侧模板的外边框对齐

将章节标题和副标题与两侧模板的外边框对齐

我在将部分标题与两面模板的外部对齐时遇到了问题。如下面的屏幕截图所示,我的部分标题不仅包含标题(出现在目录中),还包含副标题。虽然标题的对齐方式完美,但副标题始终与左侧对齐。我尝试了 raggedleft 和 raggedright(如下面的代码所示)、flushright 和解决方案,<blank line> \hspace*{\fill} <text>但对我而言都不起作用。 在此处输入图片描述

我的代码:

\RequirePackage{titlesec}
\usepackage{ifthen,changepage}
\titleformat{\section}
    {\color{ColAccent}\bfseries\sffamily\filcenter\fontsize{36pt}{43pt}\selectfont}
    {\thesection}
    {0.5em}
    {\MakeUppercase}
\titleformat{name=\subsection,page=even}
    {\color{ColAccent}\bfseries\sffamily\raggedright\fontsize{28pt}{30pt}\selectfont}
    {\thesubsection}
    {0.5em}
    {}
\titleformat{name=\subsection,page=odd}
    {\color{ColAccent}\bfseries\sffamily\raggedleft\fontsize{28pt}{30pt}\selectfont}
    {\thesubsection}
    {0.5em}
    {}
\titleformat{\subsubsection}
    {\color{Black}\bfseries\sffamily\fontsize{16pt}{22pt}\selectfont}
    {\thesubsubsection}
    {0.5em}
    {}
\titleformat{\paragraph}
    {\color{Black}\bfseries\sffamily\fontsize{14pt}{26pt}\selectfont}
    {\thesubsubsubsection}
    {0.5em}
    {}
    
\newcommand{\mysubsection}[2][]{
\ifoddpage
    \subsection{#2}
    {\sffamily\raggedleft\textbf{#1}}\\
\else
  \subsection{#2}
    {\sffamily\raggedright\textbf{#1}}\\
\fi
}

答案1

由于我没有您使用的字幕环境,因此我利用的格式paragraph来替代。

\paragraphformatO在此代码中,您可以通过修改或的定义\paragraphformatE并使用\raggedleft或来更改字幕的对齐方式\raggedright

C

所有字幕左对齐

埃

% !TeX TS-program = pdflatex

\documentclass[12pt,a4paper,twoside]{article}

\usepackage[left=4.00cm, right=3.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\usepackage{kantlipsum} % dummy text
\usepackage{xcolor}
\usepackage{mathtools}
\usepackage{titlesec} % format titles

\newcommand{\paragraphformatO}[1]{%
    \parbox[b]{0.6\textwidth}{\raggedright#1}}

%\newcommand{\paragraphformatE}[1]{% right align <<<<<<<<<<
%   \parbox[b]{0.6\textwidth}{\raggedleft#1}}

\newcommand{\paragraphformatE}[1]{% left align  <<<<<<<<<<<<<<
    \parbox[b]{0.6\textwidth}{\raggedright#1}}


\newcommand{\sectionformatE}[1]{%
{\rlap{\makebox[\dimexpr\textwidth-1pc-\marginparwidth-\evensidemargin\relax][r]{\thesubsection\hspace*{0.5em}#1}}}
}

%%  \titleformat{⟨command⟩}[⟨shape⟩]{⟨format⟩}{⟨label⟩}{⟨sep⟩}{⟨before-code⟩}[⟨after-code⟩]
\titleformat{name=\subsection, page=odd}[block]
{\filright\color{cyan}\fontsize{28pt}{30pt}\selectfont\bf\sffamily} % format subsection odd 
{\thesubsection}% format label
{0.5em} 
{}%

\titleformat{name=\subsection, page=even}[block]
{\color{cyan}\fontsize{28pt}{30pt}\selectfont\bf\sffamily} % format subsection even
{}
{0.0em} 
{\sectionformatE}%


\titlespacing*{name=\subsection, page=odd}
{-4pc} % left
{1.5ex plus .1ex minus .2ex} % before
{1.5ex minus .1ex} %after

\titlespacing*{name=\subsection, page=even}
{14pc} % left
{1.5ex plus .1ex minus .2ex} % before
{1.5ex minus .1ex} %after

%%  \titlespacing*{⟨command⟩}{⟨left⟩}{⟨before-sep⟩}{⟨after-sep⟩}[⟨right-sep⟩]   
\newlength{\rightsep}
\setlength{\rightsep}{18.5pc}

\titleformat{name=\paragraph,page=even}
{\color{black}\bfseries\sffamily\fontsize{12pt}{15pt}\selectfont}
{}% no label
{0em}
{\paragraphformatE}%

\titleformat{name=\paragraph,page=odd}
{\color{black}\bfseries\sffamily\fontsize{12pt}{15pt}\selectfont}
{}% no label
{0em}
{\paragraphformatO}%


\titlespacing*{name=\paragraph, page=even}
{\rightsep} % right sep
{0.5ex plus .1ex minus .2ex} % before
{1.5ex minus .1ex} %after

\titlespacing*{name=\paragraph, page=odd}
{-4pc} % left sep
{0.5ex plus .1ex minus .2ex} % before
{1.5ex minus .1ex} %after

\begin{document}
    
\sffamily   
\setcounter{section}{6}    

\subsection{Subsec one}
\paragraph{As any dedicated reader can clearly see, the Ideal of practical reason is a representation of  the things in themselves.}

\kant[1] 

\subsection{Subsec two}
\paragraph{As any dedicated reader can clearly see, the Ideal of practical reason is a representation of  the things in themselves.}

\kant[1]    
\newpage

\subsection{Subsec three}
\paragraph{As any dedicated reader can clearly see, the Ideal of practical reason is a representation of  the things in themselves.}

\kant[2]

\subsection{Subsec four}
\paragraph{As any dedicated reader can clearly see, the Ideal of practical reason is a representation of  the things in themselves.}

\kant[9]

\end{document}

相关内容