![如何将一个框添加为节的前缀或将一个框浮动在节的左侧?](https://linux22.com/image/272538/%E5%A6%82%E4%BD%95%E5%B0%86%E4%B8%80%E4%B8%AA%E6%A1%86%E6%B7%BB%E5%8A%A0%E4%B8%BA%E8%8A%82%E7%9A%84%E5%89%8D%E7%BC%80%E6%88%96%E5%B0%86%E4%B8%80%E4%B8%AA%E6%A1%86%E6%B5%AE%E5%8A%A8%E5%9C%A8%E8%8A%82%E7%9A%84%E5%B7%A6%E4%BE%A7%EF%BC%9F.png)
我正在将工作中的一些旧文档转换为 LaTeX。我意识到我需要做的一些事情不符合 LaTeX 排版标准,但这就是我目前的情况。我已经处理了大部分文本格式,但作为我们在职培训文件的一部分,有一些方框供培训师“签署”培训。尝试复制这些文件一直很令人头疼。任何帮助都将不胜感激。
这是 OJT 的图片
我尝试过几个不同的软件包,但没有一个能完全满足我的需要。
\documentclass{article}
\renewcommand\thepart{\arabic{part}:}
\usepackage{titlesec}
\titleformat{\part}[block]{\centering\bfseries\huge}{Part \thepart}{10pt}{}[\setcounter{section}{0}]
\usepackage{enumitem}
\setitemize[0]{itemindent=2.5cm}
%Item Prefix - \so signoff
\newcommand{\so}{\item[\underline{\hspace{0.85cm}}]}
\usepackage{lipsum}
\begin{document}
\part{Personnel Introduction}
\lipsum[1]
\section{Division Personnel}
\subsection{Headquarters}
You have had the opportunity to be introduced to Headquarters personnel, including:
\begin{itemize}
\so Name Name
\so Name Name
\end{itemize}
\subsection{Production Department}
You have had the opportunity to be introduced to some Production personnel, including:
\begin{itemize}
\so Name Name
GROUP \#1
\so Name Name
\so Name Name
\so Name Name
GROUP \#2
\so Name Name
\so Name Name
\end{itemize}
\end{document}
我的代码还差得远。我见过类似下面的代码,但显然不起作用。
\newcommand{\trainer}{
\fbox{
\resizebox{3cm}{2cm}{
\rule{2.75cm}{.4pt}
Trainer\hspace{.7cm}Date
}
}
}
\begin{document}
\part{Personnel Introduction}
\lipsum[1]
\section{Division Personnel}
\trainer\subsection{Headquarters}
You have had the opportunity to be introduced to Headquarters personnel, including:
\begin{itemize}
\so Name Name
\so Name Name
\end{itemize}
\subsection{Production Department}
You have had the opportunity to be introduced to some Production personnel, including:
\begin{itemize}
\so Name Name
GROUP \#1
\so Name Name
\so Name Name
\so Name Name
GROUP \#2
\so Name Name
\so Name Name
\end{itemize}
\end{document}
提前致谢
答案1
这里有一些选择:
\documentclass[a4paper]{article}
\usepackage[explicit,pagestyles]{titlesec}
\usepackage{enumitem}
\usepackage{changepage}
\usepackage{lastpage}
\usepackage{lipsum}% just to generate text for the example
\newlength\TIndent
\setlength\TIndent{3cm}
\makeatletter
\@addtoreset{section}{part}
\makeatother
\renewcommand\thepart{\arabic{part}}
\renewcommand\thesection{\thepart.\arabic{section}}
\renewcommand\thesubsection{\arabic{subsection}}
\newcommand\TBox{%
\fbox{\footnotesize%
\begin{tabular}{cc}
\\[1.3ex]
\hline
\\[-1.7ex]
Trainee & Date
\end{tabular}}%
}
\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}
\titleformat{\subsection}
{\normalfont\large\bfseries}{}{0em}{\llap{\smash{\makebox[\TIndent][l]{\normalfont\TBox}}}\thesubsection. #1}
\titlespacing*{\section}
{0pt}{3.5ex plus 1ex minus .2ex}{.3ex plus .2ex}
\newlist{Titemize}{itemize}{1}
\setlist[Titemize]{label={\rule{1cm}{0.4pt}},leftmargin=*}
\newpagestyle{Tstyle}{
\headrule\footrule
\sethead{Left}{Center}{Right}
\setfoot{\small 7.1.2013}{\small Introductory Training}{\small Page~\thepage of~\pageref{LastPage}}
}
\pagestyle{Tstyle}
\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\subsection{Headquarters}
\begin{Titemize}
\item \Text
\item \Text
\item \Text
\end{Titemize}
\subsection{Production Department}
\begin{Titemize}
\item \Text
\item \Text
\item \Text
\item \Text
\item \Text
\end{Titemize}
\end{adjustwidth}
\end{document}
使用的软件包:
titlesec
自定义章节单元标题,并定义页面样式(通过选项pagestyles
)。
changepage
改变部分内的缩进。
enumitem
定义一个以水平线作为标签的列表。
laspage
可以访问页脚的最后一页的页码。
答案2
虽然我知道您已经接受了解决方案,但这里有一种不同的方法。
我通常遵循@GonzaloMedina 在定义\part
和方面所做的事情\section
。但我对其余部分采取了截然不同的方法。我没有重新定义,而是决定创建两个可以相互嵌套的列表环境。考虑这种方法的主要原因是,您可能实际上在文档中还有其他您不想修改的\subsection
用途。\subsection
以下是 MWE:
产生
\documentclass{article}
%% create the trainee signature and date box
\newsavebox{\traineesignaturebox}
\savebox{\traineesignaturebox}
{\setlength{\fboxsep}{0pt}%
\renewcommand{\arraystretch}{1.25}%
\fbox{%
\begin{tabular}{cc}
\rule{0pt}{3ex}\\\hline
Trainee & Date
\end{tabular}}}
%% you don't want this box interfering with and width, hence
%% the use of `\llap`. Also, you don't want it interfering
%% with vertical spacing, hence `\smash`.
\newcommand{\traineesignature}{\llap{\smash{\usebox{\traineesignaturebox}}}}
%% Instead of redefining subsection (since you might want those for
%% another purpose in your document, create two lists to be nest.
%%-----------------------------------------------------------------
%% Here we create various lengths for structuring the outer most list.
%% These lengths are probably not necessary. But, originally, I thought
%% you might want access to their values from within the inner list.
\newlength{\checklistlabelsep}
\newlength{\checklistlabelwidth}
\newlength{\checklistitemindent}
\newlength{\checklistleftmargin}
%% setting the lengths
\setlength{\checklistlabelsep}{1em}
\setlength{\checklistitemindent}{2em}
\setlength{\checklistlabelwidth}{2em}
\setlength{\checklistleftmargin}
{\dimexpr\checklistitemindent
+\checklistlabelwidth
-\checklistlabelsep
+\wd\traineesignaturebox
-\checklistitemindent}
%% The outer list should work like an `enumerate` environment
%% so I created a counter.
\newcounter{traineeCheckListCounter}
\newenvironment{traineeCheckList}
{\begin{list}
{\traineesignature\rule{0pt}{4ex}%
\makebox[\checklistlabelwidth][r]{\large\bfseries\upshape\arabic{traineeCheckListCounter}.}}
{\usecounter{traineeCheckListCounter}
\setlength{\labelsep}{\checklistlabelsep}
\setlength{\itemindent}{\checklistitemindent}
\setlength{\labelwidth}{\checklistlabelwidth}
\setlength{\leftmargin}{\checklistleftmargin}
\setlength{\itemsep}{\baselineskip}
\setlength{\topsep}{\baselineskip}
}
}
{%
\end{list}
}
\newcommand{\divisionalCategory}[1]{\item {\large\bfseries\upshape #1}}
\newcommand{\intermediaryCategory}[1]{\vspace{1ex}\par\hspace*{3em}{\bfseries\upshape #1}\par}
%% This is the inner list.
%% This list should behave more like an `itemize` list.
\newenvironment{traineeAccomplishmentList}
{\begin{list}
{}
{
\setlength{\labelwidth}{1cm}
\setlength{\labelsep}{1em}
\setlength{\leftmargin}{\dimexpr1cm+1em}
\setlength{\itemindent}{0pt}
}
}
{\end{list}}
%% From the inner list you want to create some spaces
%% for checking things off. `\item` is not happy with
%% a `\rule` being passed through its optional argument
%% so I save this rule to a box to get around this issue.
\newsavebox{\checkoffBox}
\savebox{\checkoffBox}{\rule[-0.4pt]{1cm}{0.4pt}}
\newcommand{\accomplishment}{\item[\usebox{\checkoffBox}]}
%%--------------------------------------------------------------------------------
%% You still need a means of creating your `part` and `subparts`
%%--------------------------------------------------------------------------------
\usepackage[explicit]{titlesec}
\titleformat{\part}
{\normalfont\LARGE\bfseries\filcenter}
{\partname \ \arabic{part}:}
{0.5em}
{#1}
\titleformat{\section}
{\normalfont\Large\bfseries}
{}
{0.5\wd\traineesignaturebox}
{\arabic{part}.\thesection\hspace*{1em}#1}
%%--------------------------------------------------------------------------------
%% You need header and footers
%%--------------------------------------------------------------------------------
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\lhead{}
\chead{}
\rhead{}
\lfoot{7.1.2013}
\cfoot{Introductory Training}
\rfoot{Page \thepage\ of \pageref{LastPage}}
%% These next two lines are here just for development purposes.
%% \usepackage{showframe}
\usepackage{lipsum}
\begin{document}
\part{Personnel Introduction}
\lipsum[1]
\section{Division Personnel}
\begin{traineeCheckList}
\divisionalCategory{Headquarters}\par
A brief description of what this is about followed by a list of
accomplishments to be named.
\begin{traineeAccomplishmentList}
\accomplishment first
\accomplishment second
\intermediaryCategory{Headquarters Administration}
\accomplishment another
\accomplishment and more
\end{traineeAccomplishmentList}
\divisionalCategory{Production Department}
\begin{traineeAccomplishmentList}
\accomplishment A
\accomplishment B
\accomplishment Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.
\accomplishment C
\accomplishment D
\end{traineeAccomplishmentList}
\end{traineeCheckList}
\end{document}