Advertisement
Speravir

LaTeX: Thumbs with scrpage2

May 25th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 2.76 KB | None | 0 0
  1. %%% Source:
  2. %%% Tobi in http://tex.stackexchange.com/a/57317/9237
  3. %%% Some changes by Speravir
  4. %%%
  5. %%% Compare http://pastebin.com/hwu8c5QZ
  6.  
  7. \documentclass{book}
  8.  
  9. % load TikZ to draw the boxes
  10. \usepackage{tikz}
  11. \usetikzlibrary{calc}
  12.  
  13. % use scrpage2 or whatever you want to add
  14. % the boxes to the header to make them appear
  15. % on every page
  16. \usepackage{scrpage2}
  17. \pagestyle{scrheadings}
  18.  
  19. % new counter to hold the current number of the
  20. % letter to determine the vertical position
  21. \newcounter{letternum}
  22. % newcounter for the sum of all letters to get
  23. % the right height of a box
  24. \newcounter{lettersum}
  25. \setcounter{lettersum}{26}
  26. % some margin settings
  27. \newlength{\thumbtopmargin}
  28. \setlength{\thumbtopmargin}{1cm}
  29. \newlength{\thumbbottommargin}
  30. \setlength{\thumbbottommargin}{3cm}
  31. % calculate the box height by dividing the page height
  32. \newlength{\thumbheight}
  33. \pgfmathsetlength{\thumbheight}{%
  34.     (\paperheight-\thumbtopmargin-\thumbbottommargin)%
  35.     /%
  36.     \value{lettersum}
  37. }
  38. % box width
  39. \newlength{\thumbwidth}
  40. \setlength{\thumbwidth}{1.5cm}
  41. % style the boxes
  42. \tikzset{
  43.    thumb/.style={
  44.        fill=black!50!red,
  45.        text=white,
  46.        minimum height=\thumbheight,
  47.        text width=\thumbwidth,
  48.        outer sep=0pt,
  49.        font=\sffamily\bfseries,
  50.    }
  51. }
  52. \newcommand{\oddthumb}[1]{%
  53.         % see pgfmanual.pdf for more information about this part
  54.         \begin{tikzpicture}[remember picture, overlay]
  55.             \node [thumb,align=right,anchor=north east,] at ($%
  56.                 (current page.north east)-%
  57.                 (0,\thumbtopmargin+\value{letternum}*\thumbheight)%
  58.             $) {#1};
  59.        \end{tikzpicture}
  60. }
  61. \newcommand{\eventhumb}[1]{%
  62.         % see pgfmanual.pdf for more information about this part
  63.         \begin{tikzpicture}[remember picture, overlay]
  64.             \node [thumb,align=left,anchor=north west,] at ($%
  65.                 (current page.north west)-%
  66.                 (0,\thumbtopmargin+\value{letternum}*\thumbheight)%
  67.             $) {#1};
  68.        \end{tikzpicture}
  69. }
  70. % create a new command to set a new lettergroup
  71. \newcommand{\lettergroup}[1]{%
  72.     % add a chapter (optional)
  73.     \chapter*{#1}%
  74. %     \section*{#1}
  75.     % use one head or foot element to put in the box
  76.     % it doesn't matter which you use since the box
  77.     % is positioned on the page absolutely
  78.     \lohead[\oddthumb{#1}]{\oddthumb{#1}}%
  79.     \rehead[\eventhumb{#1}]{\eventhumb{#1}}%
  80.     % step the counter of the letters
  81.     \stepcounter{letternum}%
  82. }
  83.  
  84. % for some blindtext
  85. \usepackage{lipsum}
  86.  
  87. \begin{document}
  88.  
  89. % usage: \lettergroup{<letter>}
  90. % e.g.
  91. \lettergroup{A}
  92. % your text
  93. \lipsum[1-20]
  94.  
  95. \lettergroup{B}
  96. \lipsum[21-40]
  97.  
  98. \lettergroup{C}
  99. \lipsum[41-60]
  100.  
  101. \lettergroup{D}
  102. \lipsum[61-80]
  103. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement