5

In the following example, I've added a patch to the \chapter as an attempt to fix hyperref links. (See Hyperref chapter in twocolumn mode (without using multicols).)

\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}

This, however, gives me a weird indent only after non-starred \chapter headings. Some of the indent is removed by placing a % at the end, as \chapter{Introduction}%, but not all of it. For starred \chapter headings, the behaviour is similar, though I can remove the entire indent by using %.

The behaviour goes away when I comment out the line

\patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{}

But this fails to solve the original problem. I've looked at the scrreprt.cls file to try to eyeball a bug, but don't have the expertise to identify it. The behaviour is only present in twocolumn format.

\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
}
  • \patchcmd{\chapter}{\@afterindentfalse}{\@afterindentfalse\leavevmode}{}{} is always going to destroy the spacing after a chapter head. Not doing that would be the start, but I couldn't see a clear description of the problem you are trying to solve. – David Carlisle Mar 1 '15 at 17:07
  • It was a suggested solution to the problem of ensuring hyperlinks to chapter headings don't aim too low in twocolumn. – Hugh Mar 1 '15 at 17:10
  • Can you provide a link to that suggested solution? KOMA is very sensitive in what it is doing. – Johannes_B Mar 1 '15 at 17:21
  • tex.stackexchange.com/a/230582/18414 – Hugh Mar 1 '15 at 17:22
2

For me the combination of your code and the part of the cited question from Werner seems to work for me. The copied part starts with % copy from http://tex.stackexchange.com/questions/230577, Werner and ends at \begin{document}.

Please check the following 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}

The result for the preface:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.