同一级别的多个部分具有不同的标签

同一级别的多个部分具有不同的标签

这是问题。

我想让多个小节的标签(在本例中为签名框)都采用相同的编号顺序。我尝试这样做,但结果却把编号完全打乱了。

提前致谢。

\documentclass[a4paper,twoside]{article}
\usepackage[explicit,pagestyles]{titlesec}
\usepackage{enumitem}
\usepackage{changepage}
\usepackage{lastpage}
\usepackage{lipsum}% just to generate text for the example

%Heading formatting
\titleformat{\part}[block]
  {\normalfont\LARGE\bfseries\filcenter}{\partname\ \thepart:}{0.5em}{#1}
\titleformat{\section}
  {\normalfont\Large\bfseries}{}{\TIndent}{\llap{\makebox[0.5\TIndent][l]{\thesection}\hfill}#1}
\titlespacing*{\section}
{0pt}{3.5ex plus 1ex minus .2ex}{.3ex plus .2ex}

%Trainee section signoff
\newcounter{trainee}
\titleclass{\trainee}{straight}[\section]
\titleformat{\trainee}
    {\normalfont\large\bfseries}{}{0em}{\llap{\smash{\makebox[\TIndent][l]{\normalfont\TeBox}}}\thesubsection. #1}
\titlespacing*{\trainee}
    {0pt}{3.5ex plus 1ex minus .2ex}{.3ex plus .2ex}
\renewcommand{\thetrainee}{\Alph{trainee}}

%Trainer section signoff
\newcounter{trainer}
\titleclass{\trainer}{straight}[\section]
\titleformat{\trainer}
    {\normalfont\large\bfseries}{}{0em}{\llap{\smash{\makebox[\TIndent][l]{\normalfont\TrBox}}}\thesubsection. #1}
\titlespacing*{\trainer}
    {0pt}{3.5ex plus 1ex minus .2ex}{.3ex plus .2ex}
\renewcommand{\thetrainer}{\Alph{trainer}}

%Defines the sign off indent distance
\newlength\TIndent
\setlength\TIndent{9em}

\makeatletter
\@addtoreset{section}{part}
\makeatother
\renewcommand\thepart{\arabic{part}}
\renewcommand\thesection{\thepart.\arabic{section}}
\renewcommand\thesubsection{\arabic{subsection}}

%Trainee box
\newcommand\TeBox{%
\fbox{\footnotesize%
\begin{tabular}{cc}
\\[1.2em]
\hline
\\[-.8em]
Trainee & Date \vspace{-.4em}
\end{tabular}}%
}

%Trainer box
\newcommand\TrBox{%
\fbox{\footnotesize%
\begin{tabular}{cc}
\\[1.2em]
\hline
\\[-.8em]
Trainer & Date \vspace{-.4em}
\end{tabular}}%
}

\setitemize{label={\rule{1cm}{0.4pt}},leftmargin=*}

\newcommand\Text{% just to generate text for the example
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel,
wisi. Morbi auctor lorem non justo.}

\begin{document}
\part{Personnel Introduction}

\lipsum[4]

    \section{Division Personnel}
    \begin{adjustwidth}{3cm}{0pt}
        \leavevmode\trainee{Headquarters}

        \Text
        \begin{itemize}
        \item Name Name
        \item Name Name
        \end{itemize}

        \trainer{Production Department}

        \Text
        \begin{itemize}
        \item Name Name

        \begin{center}
        SECONDARY GROUP
        \end{center}

        \item Name Name
        \item Name Name
        \item Name Name
        \end{itemize}
    \end{adjustwidth}

\end{document}

签字示例

答案1

trainex您只需使用一个新的部分单元和一个带有可选参数的命令以及一个条件测试来决定是否使用“培训师”或“受训者”即可实现您想要的目标:

\documentclass[a4paper,twoside]{article}
\usepackage[explicit,pagestyles]{titlesec}
\usepackage{enumitem}
\usepackage{changepage}
\usepackage{lastpage}
\usepackage{lipsum}% just to generate text for the example

%Heading formatting
\titleformat{\part}[block]
  {\normalfont\LARGE\bfseries\filcenter}{\partname\ \thepart:}{0.5em}{#1}
\titleformat{\section}
  {\normalfont\Large\bfseries}{}{\TIndent}{\llap{\makebox[0.5\TIndent][l]{\thesection}\hfill}#1}
\titlespacing*{\section}
{0pt}{3.5ex plus 1ex minus .2ex}{.3ex plus .2ex}

%Trainex section signoff
% will be used for both, depending on an optional argument
\newcounter{trainex}
\titleclass{\trainex}{straight}[\section]
\titleformat{\trainex}
    {\normalfont\large\bfseries}{}{0em}{\llap{\smash{\makebox[\TIndent][l]{\normalfont\TeBox}}}\thetrainex. #1}
\titlespacing*{\trainex}
    {0pt}{3.5ex plus 1ex minus .2ex}{.3ex plus .2ex}
\renewcommand{\thetrainex}{\Alph{trainex}}

\def\trainexx{}

% Here we decide whether to use "Trainee" or "Trainer" in the box
% by default, \trainey uses "Trainer"; if the optional argument is "e"
% then "Trainee" will be used.
\newcommand\trainey[2][r]{%
\if#1r\relax
\renewcommand\trainexx{Trainer}
\else
\if#1e
\renewcommand\trainexx{Trainee}
\fi\fi
\trainex{#2}
}

%Defines the sign off indent distance
\newlength\TIndent
\setlength\TIndent{9em}

\makeatletter
\@addtoreset{section}{part}
\makeatother
\renewcommand\thepart{\arabic{part}}
\renewcommand\thesection{\thepart.\arabic{section}}
\renewcommand\thesubsection{\arabic{subsection}}

%Trainee box
\newcommand\TeBox{%
\fbox{\footnotesize%
\begin{tabular}{cc}
\\[1.2em]
\hline
\\[-.8em]
\trainexx & Date \vspace{-.4em}
\end{tabular}}%
}

%Trainer box
\newcommand\TrBox{%
\fbox{\footnotesize%
\begin{tabular}{cc}
\\[1.2em]
\hline
\\[-.8em]
Trainer & Date \vspace{-.4em}
\end{tabular}}%
}

\setitemize{label={\rule{1cm}{0.4pt}},leftmargin=*}

\newcommand\Text{% just to generate text for the example
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel,
wisi. Morbi auctor lorem non justo.}

\begin{document}
\part{Personnel Introduction}

\lipsum[4]

    \section{Division Personnel}
    \begin{adjustwidth}{3cm}{0pt}
        \leavevmode\trainey[e]{Headquarters}

        \Text
        \begin{itemize}
        \item Name Name
        \item Name Name
        \end{itemize}

        \trainey{Production Department}

        \Text
        \begin{itemize}
        \item Name Name

        \begin{center}
        SECONDARY GROUP
        \end{center}

        \item Name Name
        \item Name Name
        \item Name Name
        \end{itemize}
    \end{adjustwidth}

\end{document}

在此处输入图片描述

答案2

所以我决定使用它subsection来保存我的编号,然后手动增加数字。我测试了一下,它非常有效!

%Set initial subsection counter
\setcounter{subsection}{1}

%Trainee section signoff
\newcounter{trainee}
\titleclass{\trainee}{straight}[\section]
\titleformat{\trainee}
    {\normalfont\large\bfseries}{}{0em}{\stepcounter{subsection}\llap{\smash{\makebox[\TIndent][l]{\normalfont\TeBox}}}\thesubsection. #1}
\titlespacing*{\trainee}                   ^ %Increment subsection counter here
    {0pt}{3.5ex plus 1ex minus .2ex}{.3ex plus .2ex}
\renewcommand{\thetrainee}{\Alph{subsection}}

%Trainer section signoff
\newcounter{trainer}
\titleclass{\trainer}{straight}[\section]
\titleformat{\trainer}
    {\normalfont\large\bfseries}{}{0em}{\stepcounter{subsection}\llap{\smash{\makebox[\TIndent][l]{\normalfont\TrBox}}}\thesubsection. #1}
\titlespacing*{\trainer}                   ^ %Increment subsection counter here
    {0pt}{3.5ex plus 1ex minus .2ex}{.3ex plus .2ex}
\renewcommand{\thetrainer}{\Alph{subsection}}

手动计数器

相关内容