我正在做的一个工作格式有问题。LaTeX 的默认输出如下所示:
1.1. Section A
Latex latex latex latex.
1.1.1. Subsection A-1
Latex latex latex latex.
但我想要的格式是:
1.1. Section A
Latex latex latex latex.
1.1.1. Subsection A-1
Latex latex latex latex.
小节的编号应与节的文本位于同一垂直行,并且我想减少编号和文本之间的间距以及段落的缩进。
答案1
由于没有更好的答案,这是我的尝试。
对我的方法的一些评论。
我使用了以下示例Vincent Zoonekynd 的网页作为起点。
我将子节编号设置在特定宽度的框中,然后将子节标题设置在它的右侧。通常,
\quad
两者之间只有一个水平空间,但是一旦节编号达到两位数,就会出现对齐问题。我进行调整
\leftskip
以使凹痕达到所需的水平。\section
、\subsection
和 的缩进\subsubsection
目前分别为10mm
、12mm
和14mm
。这些数字设置在我的代码顶部(见下文)。我选择了递增的值序列来解释子小节具有较长的数字这一事实(例如 1.1.1)。
我认为我的方法存在两个主要问题。
、
\section
和\subsection
都是\subsubsection
从头开始重新定义的。一定有更简单的方法可以做到这一点,对吧?也许这个titlesec
包会有所帮助。每个((子)子)部分标题上方和下方的间距是固定的,与
article
类大致相同。这意味着如果您加载不同的类(如)book
,您将无法获得预期的间距。好的一面是,您可以非常轻松地根据自己的喜好手动调整间距。
这是代码。
\documentclass{article}
\usepackage{parskip}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Configuration
\def\sectionindent{10mm}
\def\subsectionindent{12mm}
\def\subsubsectionindent{14mm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some derived quantities
% (you should manually update these)
\def\subsectiontotalindent{22mm}
% = \sectionindent + \subsectionindent
\def\subsubsectiontotalindent{36mm}
% = \sectionindent + \subsectionindent + \subsubsectionindent
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following code is adapted from some sample code by
% Vincent Zoonekynd, made available at the following website:
% http://zoonek.free.fr/LaTeX/LaTeX_samples_section/0.html
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Redefining \section and \section*
\def\section{\@ifstar\unnumberedsection\numberedsection}
\def\numberedsection{\@ifnextchar[%]
\numberedsectionwithtwoarguments\numberedsectionwithoneargument}
\def\unnumberedsection{\@ifnextchar[%]
\unnumberedsectionwithtwoarguments\unnumberedsectionwithoneargument}
\def\numberedsectionwithoneargument#1{\numberedsectionwithtwoarguments[#1]{#1}}
\def\unnumberedsectionwithoneargument#1{\unnumberedsectionwithtwoarguments[#1]{#1}}
\def\numberedsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
\refstepcounter{section}%
\noindent
\begingroup
\leavevmode\Large\bfseries\raggedright
\rlap{\thesection}%
\hspace{\sectionindent}%
#2
\par
\endgroup
\vskip 2ex\nobreak
\addcontentsline{toc}{section}{%
\protect\numberline{\thesection}%
#1}%
\leftskip=\sectionindent\relax%
}
\def\unnumberedsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
% \refstepcounter{section}%
\noindent
\begingroup
\leavevmode\Large\bfseries\raggedright
%\rlap{\thesection}%
\hspace{\sectionindent}%
#2
\par
\endgroup
\vskip 2ex\nobreak
\addcontentsline{toc}{section}{%
% \protect\numberline{\thesection}%
#1}%
\leftskip=\sectionindent\relax%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Redefining \subsection and \subsection*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\subsection{\@ifstar\unnumberedsubsection\numberedsubsection}
\def\numberedsubsection{\@ifnextchar[%]
\numberedsubsectionwithtwoarguments\numberedsubsectionwithoneargument}
\def\unnumberedsubsection{\@ifnextchar[%]
\unnumberedsubsectionwithtwoarguments\unnumberedsubsectionwithoneargument}
\def\numberedsubsectionwithoneargument#1{\numberedsubsectionwithtwoarguments[#1]{#1}}
\def\unnumberedsubsectionwithoneargument#1{\unnumberedsubsectionwithtwoarguments[#1]{#1}}
\def\numberedsubsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
\refstepcounter{subsection}%
\noindent
\begingroup
\leavevmode\large\bfseries\raggedright
\hspace{\sectionindent}%
\rlap{\thesubsection}%
\hspace{\subsectionindent}%
#2
\par
\endgroup
\vskip 2ex\nobreak
\addcontentsline{toc}{subsection}{%
\protect\numberline{\thesubsection}%
#1}%
\leftskip=\subsectiontotalindent\relax%
}
\def\unnumberedsubsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
% \refstepcounter{subsection}%
\noindent
\begingroup
\leavevmode\large\bfseries\raggedright
\hspace{\sectionindent}%
%\rlap{\thesubsection}%
\hspace{\subsectionindent}%
#2
\par
\endgroup
\vskip 2ex\nobreak
\addcontentsline{toc}{subsection}{%
% \protect\numberline{\thesubsection}%
#1}%
\leftskip=\subsectiontotalindent\relax%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Redefining \subsubsection and \subsubsection*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\subsubsection{\@ifstar\unnumberedsubsubsection\numberedsubsubsection}
\def\numberedsubsubsection{\@ifnextchar[%]
\numberedsubsubsectionwithtwoarguments\numberedsubsubsectionwithoneargument}
\def\unnumberedsubsubsection{\@ifnextchar[%]
\unnumberedsubsubsectionwithtwoarguments\unnumberedsubsubsectionwithoneargument}
\def\numberedsubsubsectionwithoneargument#1{\numberedsubsubsectionwithtwoarguments[#1]{#1}}
\def\unnumberedsubsubsectionwithoneargument#1{\unnumberedsubsubsectionwithtwoarguments[#1]{#1}}
\def\numberedsubsubsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
\refstepcounter{subsubsection}%
\noindent
\begingroup
\leavevmode\normalsize\bfseries\raggedright
\hspace{\subsectiontotalindent}%
\rlap{\thesubsubsection}%
\hspace{\subsubsectionindent}%
#2
\par
\endgroup
\vskip 2ex\nobreak
\addcontentsline{toc}{subsubsection}{%
\protect\numberline{\thesubsubsection}%
#1}%
\leftskip=\subsubsectiontotalindent\relax%
}
\def\unnumberedsubsubsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
% \refstepcounter{subsubsection}%
\noindent
\begingroup
\leavevmode\normalsize\bfseries\raggedright
\hspace{\subsectiontotalindent}%
%\rlap{\thesubsubsection}%
\hspace{\subsubsectionindent}%
#2
\par
\endgroup
\vskip 2ex\nobreak
\addcontentsline{toc}{subsubsection}{%
% \protect\numberline{\thesubsubsection}%
#1}%
\leftskip=\subsubsectiontotalindent\relax%
}
\makeatother
\parindent=0pt
\newcommand\randomtext{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ac lorem ac justo auctor elementum. Ut mattis mauris et orci mollis sollicitudin.\par}
\begin{document}
\randomtext
\section{Introduction}
\randomtext
\randomtext
\subsection{Subsection}
\randomtext
\subsubsection{Subsubsection}
\randomtext
\subsubsection*{Subsubsection without a number}
\randomtext
\subsubsection{Subsubsection with a number}
\randomtext
\subsection{Another subsection}
\randomtext
\subsubsection{Hello}
\randomtext
\section{Hello}
\randomtext
\section{Hello}
\randomtext
\section{Hello}
\randomtext
\section{Hello}
\randomtext
\section{Hello}
\randomtext
\section{Hello}
\randomtext
\section{Hello}
\randomtext
\section{Hello}
\randomtext
\section{Hello}
\randomtext
\end{document}