Advertisement
Speravir

LaTeX: Thumbs with fancyhdr

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