1

I have a very long longtable (>100 pages) with 4 columns which represents an index into some literary text. The index data is programmatically produced and I have removed the first (index element) for all but its first occurance. There are cases, where for one index element follow many lines and there are therefore pages where there is no index element shown at all.

The page should look like:

Header A-Entry 

        value1  value2 .. which is the continuation of A-entry
        value3  value4
        ... many more A-entry lines till a new index entry
B-entry value5 value6 
        value7 value8 
C-entry ...

I see three approaches for a solution:

  1. Show the current (i.e. last seen) index entry in the page header.
  2. Remove the index in the first column when it is repeated within a page by a latex function.
  3. Put the current (i.e. last seen) index in the header of the longtable.

I have seen in this question a solution using struts but have not found any other documentation. Is this a path to a solution of my problem?

My current solution (following the advice received) is:

\documentclass{article}
\usepackage[german]{babel}  
\usepackage{booktabs,array,microtype, longtable}
\usepackage{alltt}  % to use input with commands 
\usepackage{fontspec}
\newfontfamily{\tablefont}{ebgaramond}
\usepackage{lmodern} % to avoid scalable font error
\usepackage[automark,headsepline,plainheadsepline]{scrlayer-scrpage}

\begin{document}

\newcommand{\dohang}{\hangindent1em\hangafter1 }
     \begin{scriptsize}\tablefont
        \mark{ AAA3mal}
        \begin{longtable}{@{}
                l
                >{\everypar{\dohang}\dohang\raggedright\arraybackslash}p{18mm} 
                >{\everypar{\dohang}\dohang\raggedright\arraybackslash}p{55mm} 
                >{\everypar{\dohang}\dohang\raggedright\arraybackslash}p{26mm}
                 p{9mm}}
            {} & Lemma & Gedichtzeile & Gedichttitel & Index \\\\
            \endfirsthead

      \markboth{Trankst}{Trankst}&Trankst & Trankst du begierig, durst'ger Greis! & Am Sarg eines & 7:1-12\\
       \markboth{traulich}{traulich}&traulich & Wo, traulich sich dran schmiegend, es & Im Schnee & 1:1-13\\
       \markboth{träumend}{träumend}&träumend & Welche träumend drinnen schliefen & Himmelsleiter & 5:2-1\\
       \markboth{Türe}{Türe}&Türe & Hockt vor der Tür und flickt die alten Schuh. & Wie glänzt der helle &
        \end{longtable}
    \end{scriptsize}
\end{document}

The solution works because I have (programmatically) produced the data lines to form the index and added to each line a \markboth{XXX}{XXX}& or just & when no entry XXX starts. Second, I added an empty column with type "l" with header "{}", because a "p" column does not trigger the \mark command. It works but would not work with the simpler \mark.

user855443
  • 1,120
  • 2
    longtable supports using \marks to affect the page header but if you want to change the table \endhead lines to show the last index entry then see https://tex.stackexchange.com/questions/263597/change-endhead-in-the-middle-of-a-longtable (either answer may be suitable) – David Carlisle Jun 08 '19 at 16:35
  • thank you - I will try it tomorrow! – user855443 Jun 08 '19 at 20:57
  • I follwed the advice - thank you very much! The only issue remaining is that the first character of the mark is lost? where is the error? – user855443 Jun 11 '19 at 13:22
  • use \markboth{aa}{bb} or \markright{aaa} not the primitive \mark in latex – David Carlisle Jun 11 '19 at 13:47
  • perfect! I will change the code above - or do you want to publish an answer I can accept? -- Is there a way to make the first "l" column disappear or unnecessary or change the margin? The first visible column is currently indented. -- Thank you very much for help! – user855443 Jun 11 '19 at 16:07
  • you can answer if you have it working:-) – David Carlisle Jun 11 '19 at 16:36
  • Not perfect: the header is on the left taken from the last line of the page and on the right from the first line on the page. Can this be corrected? – user855443 Jun 11 '19 at 16:38
  • you can specify what information the left and right page head using fancyhdr, sorry no time now or maybe you want \markboth rather than \markright or ... – David Carlisle Jun 11 '19 at 16:41

1 Answers1

1

I have received advice and found other hints; especially useful was a template 'dictionary.tex'. The solution with KOMAscript scrbook is very simple, just 3 lines:

 \usepackage[automark,headsepline,plainheadsepline]{scrlayer-scrpage}
    \rehead{\leftmark}  \rohead{\leftmark}
    \lehead{\rightmark}     \lohead{\rightmark}

The trick is to set the right header to \leftmark (the last one seen) and the left header to \rightmark (the first one seen).

as a complete MWE:

\documentclass{scrbook}

\usepackage{booktabs,array,microtype, longtable}

\usepackage[automark,headsepline,plainheadsepline]{scrlayer-scrpage}
\rehead{\leftmark}  \rohead{\leftmark}
\lehead{\rightmark}     \lohead{\rightmark}


\begin{document}

\newcommand{\dohang}{\hangindent1em\hangafter1 }
        \begin{longtable}{@{}
                l
                >{\everypar{\dohang}\dohang\raggedright\arraybackslash}p{18mm} 
                >{\everypar{\dohang}\dohang\raggedright\arraybackslash}p{55mm} 
                >{\everypar{\dohang}\dohang\raggedright\arraybackslash}p{26mm}
                 p{9mm}}
            {} & Lemma & Gedichtzeile & Gedichttitel & Index \\\\
            \endfirsthead

%           \input{index}           
\markboth{Abendsäuseln}{Abendsäuseln}&Abendsäuseln & Eingelullt von Abendsäuseln, & Himmelsleiter & 5:1-3\\
\markboth{abgedorrt}{abgedorrt}&abgedorrt & Doch endlich abgedorrt! & Am Sarg eines & 7:1-3\\
\markboth{alt}{alt}&alt & Hockt vor der Tür und flickt die alten Schuh. & Wie glänzt der helle & 2:1-14\\
\markboth{alt}{alt}& & So ist die alte Eiche & Am Sarg eines & 7:1-2\\
\markboth{anfüllen}{anfüllen}&anfüllen & Angefüllt wird jedes Tal, & Am Himmelfahrtstage & 4:1-6\\
\markboth{Auge}{Auge}&Auge & Und ein Spielen vor den Augen & Himmelsleiter & 5:1-7\\
\markboth{ausklingen}{ausklingen}&ausklingen & Ein ausgeklungen Gotteswort. & Am Sarg eines & 7:1-6\\
\markboth{außenßen}{außenßen}&außenßen & Kein Neider schilt's, nicht aussen und nicht innen. & Jeder Schein trügt & 6:1-4\\
\markboth{aussterben}{aussterben}&aussterben & Ausgestorben scheint die Stadt, & Am Himmelfahrtstage & 4:1-1\\
\markboth{begeben}{begeben}&begeben & Sich hinaus begeben hat & Am Himmelfahrtstage & 4:1-4\\
\markboth{begierig}{begierig}&begierig & Trankst du begierig, durst'ger Greis! & Am Sarg eines & 7:1-12\\
\markboth{beginnen}{beginnen}&beginnen & Da begann von Licht und Blumen & Himmelsleiter & 5:1-5\\
\markboth{Berg}{Berg}&Berg & Auf die Hügel, auf die Berge, & Am Himmelfahrtstage & 4:1-5\\
\markboth{bescheiden}{bescheiden}&bescheiden & Dem warm ein Herz beschieden ist, & Im Schnee & 1:1-11\\
\markboth{blühende}{blühende}&blühende & Verschwunden ist die blühende & Im Schnee & 1:1-5\\
\markboth{Blume}{Blume}&Blume & Da begann von Licht und Blumen & Himmelsleiter & 5:1-5\\
\markboth{Blume}{Blume}& & Kosend durch die Blumen liefen. & Himmelsleiter & 5:2-3\\
\markboth{brennen}{brennen}&brennen & Das heimlich loht und brennt! & Im Schnee & 1:1-12\\
\markboth{Bund}{Bund}&Bund & Und den Bund mit ihm erneut, & Am Himmelfahrtstage & 4:1-3\\
        \end{longtable}
\end{document}
user855443
  • 1,120