我有一份报告的文档样式,需要将其复制到 LaTeX 格式。我使用的是 pdfLaTeX,仅供参考。本质上,该系统是段落与小节处于同一级别,直到一个部分的第一个小节,之后段落处于小节以下的级别。
它看起来应该是这样的:
1.00 第一部分
1.01 这是第一节中小节级别的段落。
1.02 这也是第一节中小节级别的段落。
1.03 第一小节
1.03.1 这是第一节第一小节的段落级别的段落。
1.03.2 这是第一节第一小节的段落级别的段落。
1.04 第二小节
1.04.1 这是第一节第二小节的段落级别的段落。
尽管我已经使用 LaTeX 很长时间了,但我还是无法掌握这种风格。我得到的是以下 MWE:
\documentclass{article}
%%% TITLE DEFINITIONS %%%
\usepackage{chngcntr} % change the display of counters
\counterwithin{table}{section}
\counterwithin{paragraph}{subsection} % paragraphs counted within subsections
\usepackage[tiny,raggedright,uppercase,noindentafter,toctitles,explicit]%
{titlesec}
\newcommand*{\newpar}{\paragraph{}}
\newcounter{paraintro}[section]
\setcounter{paraintro}{0}
\makeatletter
\@addtoreset{paragraph}{section}
\@addtoreset{subsection}{section}
\renewcommand\thesection{\arabic{section}.\two@digits{\arabic{subsection}}}
\renewcommand\thesubsection{%
\ifnum\arabic{paraintro}>0%
\addtocounter{subsection}{\arabic{paraintro}}%
\fi%
\arabic{section}.\two@digits{\arabic{subsection}}%
\addtocounter{paraintro}{-\arabic{paraintro}}%
}
\renewcommand\theparagraph{%
\ifnum\arabic{subsection}<1%
\addtocounter{paraintro}{1}%
\arabic{section}.\two@digits{\arabic{paraintro}}%
\else
\arabic{section}.\two@digits{\arabic{subsection}}.\arabic{paragraph}%
\fi
}
\renewcommand{\thetable}{%
\arabic{section}.\two@digits{\arabic{subsection}} (\alph{table})%
}
\let\oldsection\section
\newcommand{\mysection}[1]{\oldsection{\uppercase{#1}}}
\def\section{\@ifstar{\oldsection}{\mysection}}
\makeatother
\setcounter{secnumdepth}{5}
\begin{document}
\section{First Section}\label{sec:first}
\newpar This is a paragraph at subsection level in the first section.\label{intropar:first}
\newpar This is also a paragraph at subsection level in the first section.It comes after intropar \ref{intropar:first}. \label{intropar:second}
\subsection{First Subsection}\label{ssec:first}
\newpar This is a paragraph at paragraph level in subsection \ref{ssec:first} in section \ref{sec:first}.\label{par:first}
\newpar This is a paragraph at paragraph level in subsection \ref{ssec:first} in section \ref{sec:first}. It comes after paragraph \ref{par:first}.\label{par:second}.
\subsection{Second Subsection}\label{ssec:second}
\newpar This is a paragraph at paragraph level in subsection \ref{ssec:second} in section \ref{sec:first}. It comes after paragraphs \ref{par:first} and \ref{par:second}.\label{par:third}
\end{document}
这并没有给我想要的结果;数字乱七八糟。似乎引用把事情搞砸了。我怀疑这与调用\theparagraph
及其同类\ref
有关,但我已经搞砸了很长时间,不知道如何解决这个问题。
有人能帮忙吗?
答案1
使用条件。
\documentclass{article}
\usepackage[tiny,raggedright,uppercase,noindentafter,toctitles,explicit]%
{titlesec}
\usepackage{chngcntr} % change the display of counters
\newcommand*{\newpar}{%
\ifsubsection\else\stepcounter{subsection}\fi
\paragraph{}}
%%% A conditional for knowing whether a \subsection
%%% command has been issued
\newif\ifsubsection
\usepackage{etoolbox}
%%% Set the conditional to true after \subsection
%%% and reset the paragraph counter
\preto{\subsection}{\global\subsectiontrue\setcounter{paragraph}{0}}
%%% Reset it to false after \section
\preto{\section}{\global\subsectionfalse}
\counterwithin*{paragraph}{section}
\makeatletter
\renewcommand\thesection{\arabic{section}.\two@digits\c@subsection}
\renewcommand\thesubsection{\thesection}
\renewcommand\theparagraph{%
\ifsubsection
\arabic{section}.\two@digits\c@subsection.\arabic{paragraph}%
\else
\arabic{section}.\two@digits\c@paragraph
\fi
}
%%% Tables
\counterwithin*{table}{section}
\renewcommand{\thetable}{%
\arabic{section}.\two@digits\c@subsection~(\alph{table})%
}
\makeatother
\setcounter{secnumdepth}{5}
\begin{document}
\section{First Section}\label{sec:first}
\newpar This is a paragraph at subsection level in the first section.\label{intropar:first}
\newpar This is also a paragraph at subsection level in the first section.It comes after
intropar \ref{intropar:first}. \label{intropar:second}
\subsection{First Subsection}\label{ssec:first}
\newpar This is a paragraph at paragraph level in subsection \ref{ssec:first} in section
\ref{sec:first}.\label{par:first}
\newpar This is a paragraph at paragraph level in subsection \ref{ssec:first} in section
\ref{sec:first}. It comes after paragraph \ref{par:first}.\label{par:second}
\subsection{Second Subsection}\label{ssec:second}
\newpar This is a paragraph at paragraph level in subsection \ref{ssec:second} in section
\ref{sec:first}. It comes after paragraphs \ref{par:first} and
\ref{par:second}.\label{par:third}
\section{Second Section}
\newpar This is a paragraph at subsection level in the first section.
\newpar This is also a paragraph at subsection level in the first section.
\subsection{First Subsection}
\newpar This is a paragraph at paragraph level.
\newpar This is a paragraph at paragraph level.
\subsection{Second Subsection}
\newpar This is a paragraph at paragraph level in subsection.
\end{document}