在以下示例中,我添加了一个补丁,以\chapter
尝试修复超链接。(参见双列模式下的 Hyperref 章节(不使用多列)。
\documentclass[parskip=half]{scrreprt}
\usepackage{hyperref}
\usepackage[twocolumn,landscape]{geometry}
\usepackage{etoolbox}
\makeatletter
\def\tmphook{\setlength{\HyperRaiseLinkLength}{\glueexpr\scr@chapter@sectionafterskip+35pt\relax}}
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{}
\patchcmd{\Hy@raisedlink}{\ifvmode}{\let\HyperRaiseLinkHook\tmphook\ifvmode}{}{}
\makeatother
\usepackage{lipsum}
\begin{document}
\tableofcontents
\chapter*{Preface}%
\lipsum[1-5]
\chapter{Introduction}
\lipsum[1-5]
\section{Lipsum}
\lipsum[1-3]
\end{document}
但是,这只会在非星号标题后产生奇怪的缩进。通过在末尾\chapter
放置 a 可以删除部分缩进,如,但不是全部。对于带星号的标题,行为类似,但我可以使用 删除整个缩进。%
\chapter{Introduction}%
\chapter
%
当我注释掉该行时,此行为就会消失
\patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{}
但这无法解决原始问题。我查看了文件scrreprt.cls
,试图目测出错误,但没有专业知识来识别它。该行为仅存在于twocolumn
格式中。
\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{\chapterpagestyle}%
\global\@topnum\z@
\@afterindentfalse
\SecDef\@chapter\@schapter
}
\newcommand*{\@chapter}{}
\def\@chapter[#1]#2{%
\ifnum \scr@osectarg=\z@
\@scr@tempswafalse
\else
\scr@istest#1=\@nil
\fi
\if@scr@tempswa
\setkeys{KOMAarg.section}{tocentry={#2},head={#2},#1}%
\else
\ifcase \scr@osectarg\relax
\setkeys{KOMAarg.section}{tocentry={#1},head={#1}}%
\or
\setkeys{KOMAarg.section}{tocentry={#2},head={#1}}%
\or
\setkeys{KOMAarg.section}{tocentry={#1},head={#2}}%
\or
\setkeys{KOMAarg.section}{tocentry={#1},head={#1}}%
\fi
\fi
\ifnumbered{chapter}{%
\refstepcounter{chapter}%
\@maybeautodot\thechapter
\typeout{\@chapapp\space\thechapter.}%
\ifx\scr@ds@tocentry\@empty\else
\addchaptertocentry{\thechapter}{\scr@ds@tocentry}%
\fi
}{%
\ifx\scr@ds@tocentry\@empty\else
\addchaptertocentry{}{\scr@ds@tocentry}%
\fi
}%
\expandafter\chaptermark\expandafter{\scr@ds@head}%
\ifdim \@chapterlistsgap>\z@
\doforeachtocfile{%
\iftocfeature{\@currext}{chapteratlist}{%
\addtocontents{\@currext}{\protect\addvspace{\@chapterlistsgap}}%
}{}%
}%
\@ifundefined{float@addtolists}{}{%
\scr@float@addtolists@warning
\float@addtolists{\protect\addvspace{\@chapterlistsgap}}%
}%
\fi
\if@twocolumn
\if@at@twocolumn
\@makechapterhead{#2}%
\else
\@topnewpage[\@makechapterhead{#2}]%
\fi
\else
\@makechapterhead{#2}%
\@afterheading
\fi
}
\newcommand*{\@makechapterhead}[1]{%
\use@chapter@o@preamble
\@@makechapterhead{#1}%
\use@preamble{chapter@u}%
}
\newcommand*{\@@makechapterhead}[1]{%
\@tempskipa=\glueexpr \scr@chapter@sectionbeforeskip\relax
\ifdim\@tempskipa<\z@\@tempskipa-\@tempskipa\fi
\chapterheadstartvskip
{%
\setlength{\parindent}{\z@}\setlength{\parfillskip}{\fill}%
\normalfont\sectfont\nobreak\nobreak\usekomafont{chapter}{}%
\def\IfUseNumber{\ifnumbered{chapter}}%
\if@chapterprefix
\raggedchapter
\let\IfUsePrefixLine\@firstoftwo
\let\@tempa\@firstofone
\else
\let\IfUsePrefixLine\@secondoftwo
\let\@tempa\@hangfrom
\fi
\@tempa{%
\IfUseNumber{%
\usekomafont{chapter}{%
\IfUsePrefixLine{%
{\usekomafont{chapterprefix}{%
\chapterformat\chapterheadmidvskip
}}%
}{%
\chapterformat
}%
}%
}{}%
}%
{%
\IfUsePrefixLine{}{\raggedchapter}%
\interlinepenalty \@M
\usekomafont{chapter}{#1}\par
}%
}%
\nobreak\par\nobreak
\@tempskipa=\glueexpr \scr@chapter@sectionafterskip\relax
\ifdim\@tempskipa<\z@\@tempskipa-\@tempskipa\fi
\chapterheadendvskip
}
答案1
对我来说,您的代码和 Werner 所引用问题的部分的组合似乎对我有用。复制的部分以 开始% copy from http://tex.stackexchange.com/questions/230577, Werner
并结束于\begin{document}
。
请检查以下 MWE:
\documentclass[parskip=half]{scrreprt}
\usepackage[twocolumn,landscape]{geometry}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{etoolbox}
%\makeatletter
%\def\tmphook{\setlength{\HyperRaiseLinkLength}{\glueexpr\scr@chapter@sectionafterskip+35pt\relax}}
%% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
%\patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{}
%\patchcmd{\Hy@raisedlink}{\ifvmode}{\let\HyperRaiseLinkHook\tmphook\ifvmode}{}{}
%\makeatother
% copy from http://tex.stackexchange.com/questions/230577, Werner
% Add extra hyper target for chapter: chapter..\thechapter
\renewcommand*{\chapterformat}{%
\mbox{\raisebox{25pt}[0pt][0pt]{\hypertarget{chapter..\thechapter}{}}% Add
\chapappifchapterprefix{\nobreakspace}\thechapter\autodot\enskip}%
}
\makeatletter
% Update \addcontentsline to jump to new hyper target _only_ if \chapter is used
\patchcmd{\addcontentsline}% <cmd>
{\Hy@writebookmark}% <search>
{\ifnum\pdfstrcmp{chapter}{#2}=0 % Chapter mark
\edef\@currentHref{chapter..\thechapter}%
\fi
\Hy@writebookmark}% <replace>
{}{}% <success><failure>
\makeatother
\begin{document}
\tableofcontents
\chapter*{Preface}%
\lipsum[1-5]
\chapter{Introduction}
\lipsum[1-5]
\section{Lipsum}
\lipsum[1-3]
\end{document}
序言的结果: