![makebox 出现意外换行](https://linux22.com/image/478871/makebox%20%E5%87%BA%E7%8E%B0%E6%84%8F%E5%A4%96%E6%8D%A2%E8%A1%8C.png)
我认为这张图片很好地解释了我的问题:
奇数页上的章节枚举应与所有其他标题的行为相同(例如图片上的副标题)。我不明白为什么它不起作用。也许有人有主意?
这是我的代码:
\documentclass[twoside]{scrreprt}
\usepackage{blindtext}
% Align titles to outer side
\renewcommand*{\raggedsection}{\ifthispageodd{\raggedleft}{\raggedright}}
% Push section enumeration outward
\renewcommand*{\sectionlinesformat}[4]{%
\ifthispagewasodd
#4\makebox[0pt][l]{\hskip\marginparsep #3}%
\else
\makebox[0pt][r]{#3\hskip\marginparsep}#4%
\fi
}
% Push chapter enumeration outward
\makeatletter
\renewcommand*{\chapterlinesformat}[3]{%
\ifthispagewasodd
#3\makebox[0pt][l]{\hskip\marginparsep #2}% % THE ERROR SHOULD BE HERE?
\else
\makebox[0pt][r]{#2\hskip\marginparsep}#3%
\fi
}
\makeatother
\renewcommand*{\chapterformat}{\thechapter\autodot}
\renewcommand*{\sectionformat}{\thesection\autodot}
\renewcommand*{\subsectionformat}{\thesubsection\autodot}
\renewcommand*{\subsubsectionformat}{\thesubsubsection\autodot}
\begin{document}
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\end{document}
答案1
如果我添加\showtokens{#3}
重新定义的主体\chapterlinesformat
,我得到
> \interlinepenalty \@M Another Chapter\@@par .
这也解释了为什么数字会出现在下一行:(\par
原始数字)添加在章节标题的末尾。
我们必须将其移除\@@par
并重新插入到其原来的位置。
\documentclass[twoside]{scrreprt}
\usepackage{blindtext}
% Align titles to outer side
\renewcommand*{\raggedsection}{\ifthispageodd{\raggedleft}{\raggedright}}
% Push section enumeration outward
\renewcommand*{\sectionlinesformat}[4]{%
\ifthispagewasodd
#4\makebox[0pt][l]{\hskip\marginparsep #3}%
\else
\makebox[0pt][r]{#3\hskip\marginparsep}#4%
\fi
}
% Push chapter enumeration outward
\makeatletter
\renewcommand*{\chapterlinesformat}[3]{%
\ifthispagewasodd
\remove@@par#3\makebox[0pt][l]{\hskip\marginparsep #2}\@@par
\else
\makebox[0pt][r]{#2\hskip\marginparsep}#3%
\fi
}
\def\remove@@par#1\@@par{#1}
\makeatother
\renewcommand*{\chapterformat}{\thechapter\autodot}
\renewcommand*{\sectionformat}{\thesection\autodot}
\renewcommand*{\subsectionformat}{\thesubsection\autodot}
\renewcommand*{\subsubsectionformat}{\thesubsubsection\autodot}
\begin{document}
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\end{document}