我想要有章节和单个数字的段落,例如
2.3.1 Frobnication
§1 Foo bar frob
我做到了。但是当我参考这段话时……
\myref{Paragraph's Label}
...但我所能实现的一切看起来像:
See §1 (p. 1).
但我希望它像这样:
See Section 2.3.1, §1 (p.1)
目前,这是我的参考命令和我的更新\theparagraph
:
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{§\arabic{paragraph}}
\newcommand{\pararef}[1]{\ref{#1} (p. \pageref{#1})}
我目前的解决方法是给 增加两个参数\pararef
,但感觉不太干净且笨拙。
答案1
您可以定义一个“引用前缀”:如果foo
是一个计数器,那么当标签引用它时它的值将被打印为
\p@foo\thefoo
其中\p@foo
默认为空。因此
\documentclass{article}
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{\S~\arabic{paragraph}}
\newcommand{\pararef}[1]{\ref{#1} (p.~\pageref{#1})}
\makeatletter
\renewcommand{\p@paragraph}{\thesubsubsection, }
\makeatother
\begin{document}
\section{A}
\subsection{B}
\subsubsection{C}
\paragraph{D}\label{x}
This is the reference: \pararef{x}
\end{document}
如果你不总是使用\paragraph
从属于小节的句子,那么你可以说
\makeatletter
\renewcommand{\p@paragraph}{%
\ifnum\value{subsection}=\z@
\thesection
\else
\ifnum\value{subsubsection}=\z@
\thesubsection
\else
\thesubsubsection
\fi
\fi,\space
}
\makeatother
假设\paragraph
至少从属于一个部分。这是一个测试文档
\documentclass{article}
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{\S~\arabic{paragraph}}
\newcommand{\pararef}[1]{\ref{#1} (p. \pageref{#1})}
\makeatletter
\renewcommand{\p@paragraph}{%
\ifnum\value{subsection}=\z@
\thesection
\else
\ifnum\value{subsubsection}=\z@
\thesubsection
\else
\thesubsubsection
\fi
\fi,\space
}
\makeatother
\begin{document}
\section{A}
\subsection{B}
\subsubsection{C}
\paragraph{D}\label{x}
This is the reference: \pararef{x}
\section{E}
\paragraph{F}\label{y}
This is the reference: \pararef{y}
\section{G}
\subsection{H}
\paragraph{I}\label{z}
This is the reference: \pararef{z}
\end{document}
我一直认为这种交叉引用很繁琐且对读者不友好。
答案2
我将在下面保留我的原始答案,以便评论有意义,但更好的解决方案是使用内置的交叉引用前缀机制(默认情况下不用于部分,但用于嵌套列表)。该命令\p@paragraph
用于任何交叉引用文本的开头(但当计数器直接打印在标题中时,则不适用)
\documentclass{article}
\makeatletter
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{\P\arabic{paragraph}}
\newcommand{\pararef}[1]{\ref{#1} (p. \pageref{#1})}
\def\p@paragraph{Section \@currentlabel\ }
\makeatother
\begin{document}
\section{jhg}
\paragraph{jj}\label{jj}
\subsection{ljhg}
\subsubsection{lkb ljhg}
\paragraph{jjj}\label{foo}
jhgg
\section{ojh}
See \pararef{foo} and \pararef{jj}
\end{document}
原始答案:
\theparagraph
一种方法是在制作标题时放入长格式但不打印所有内容:
\documentclass{article}
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{\protect\myswitch{Section \thesubsubsection\ }\P\arabic{paragraph}}
\newcommand{\pararef}[1]{\ref{#1} (p. \pageref{#1})}
\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
{3.25ex \@plus1ex \@minus.2ex}%
{-1em}%
{\let\myswitch\@gobble\normalfont\normalsize\bfseries}}
\def\myswitch#1{#1}
\makeatother
\begin{document}
\section{jhg}
\subsection{ljhg}
\subsubsection{lkb ljhg}
\paragraph{jjj}\label{foo}
jhgg
\section{ojh}
See \pararef{foo}
\end{document}