Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to create a document where section titles are tikz nodes, and i would like to connect the nodes in every page with a path starting from the top righth corner of the page in every page. Is this possible?

Edit from Gonzalo (adding information provided by str. in a comment to my first answer):

What I initially wanted is a line that connects the upper right corner of the page with the right of the first section, and then the left of the first section to the left of the second, etc. so it would be something like corner-|section 1 -|-section 2 (etc), sort of like a snake. I can do it in tikz manually, but i would like to do it automatically in every page.

share|improve this question
1  
Hi str, welcome to the site! It would be good if you could include a minimal example document that shows how you generate the title TikZ nodes, and if you could provide some more detail on how you want to connect the corner with the nodes (I'm assuming you don't just want a straight line?) –  Jake Nov 23 '12 at 11:43
    
I am not sure if this is of any help, but I had a similar question and this is the response I got from the group. tex.stackexchange.com/questions/79121/… –  Raama Nov 23 '12 at 13:11
    
I added to the question part of your comment to my answer, so it is clear for everyone what the intended design was; I hope it's OK. –  Gonzalo Medina Nov 23 '12 at 21:13
add comment

1 Answer

If I understand the question correctly, you can use TikZ together with the titlesec package to do the job; something along these lines:

\documentclass{article}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}

\titleformat{\section}
  {\normalfont\Large\bfseries}
  {\tikz[remember picture,overlay,baseline=-6pt]
    \node[fill=cyan!60!black,minimum width=1.5em,align=center] (a) {\thesection};}
  {1em}
  {\tikz[remember picture,overlay]
    {\draw[cyan!60!black,ultra thick] 
      (a.west) -- +(-10pt,0pt)  |- ([xshift=-20pt,yshift=-20pt]current page.north east);
    \node[fill=cyan!60!black,minimum width=1em,minimum height=1em] 
      at ([xshift=-20pt,yshift=-20pt]current page.north east) {};
    }%  
  }

\begin{document}

\section{Test Section One}
\lipsum[1-4]
\section{Test Section Two}
\lipsum[1-4]
\section{Test Section Three}
\lipsum[4]

\end{document}

enter image description here

In a comment, str. has explained the design he/she wants to achieve; the idea is to get a snake pattern, formed with straight horizontal and vertical rules, zig-zagging through the sections of the document. This requires considerably more job, but is still possible; the code needs three or four runs to stabilize and some work has still to be done for the case of a page break near a section start:

\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{titlesec}
\usepackage{refcount}
\usepackage{xifthen}
\usepackage{atbegshi}
\usepackage{etoolbox}
\usepackage{lipsum}

\newcommand\pos{}
\newcounter{seccount}
\newcounter{linepages}
\newlength\linesep
\newlength\linesepaux
\newlength\mylinewidth

\setlength\linesep{40pt}
\colorlet{mycolor}{cyan!60!black}
\setlength\mylinewidth{6pt}

\setlength\linesepaux{\linesep}
\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay] \coordinate (#1) {};}

\titleformat{\section}
  {\normalfont\Large\bfseries}
  {\thesection}
  {1em}
  {\begin{tikzpicture}[remember picture,overlay]
    \draw[line width=\mylinewidth,mycolor] ([xshift=\the\dimexpr\linesepaux+0.5\mylinewidth\relax]current page text area.east|-s-\the\numexpr\thesection-1\relax) -- 
([xshift=\the\dimexpr-\linesepaux-0.5\mylinewidth\relax]current page text area.west|-s-\the\numexpr\thesection-1\relax);
\end{tikzpicture}%
  }

\newcommand\StartSecLine{%
  \stepcounter{seccount}
  \ifthenelse{\isodd{\theseccount}}
    {\global\renewcommand\pos{current page text area.north west}%
      \global\setlength\linesep{\linesepaux}}
    {\global\renewcommand\pos{current page text area.north east}%
      \global\setlength\linesep{-\linesepaux}}
  \tikzmark{e-\theseccount}\label{e-\theseccount}%
  \ifnum
    \getpagerefnumber{e-\theseccount}=\getpagerefnumber{s-\theseccount}\relax
  \else
    \begin{tikzpicture}[overlay, remember picture]
      \draw [line width=\mylinewidth,mycolor]
        ([xshift=-\linesep]\pos|-e-\theseccount) -- ([xshift=-\linesep]\pos|-current page text area.south);
    \end{tikzpicture}
    \setcounter{linepages}{\numexpr\getpagerefnumber{s-\theseccount}-\getpagerefnumber{e-\theseccount}}
    \ifnum\value{linepages}>1
      \AtBeginShipoutNext{\tikzlinepage}%
    \fi%
  \fi%
}

\newcommand\EndSecLine{%
\tikzmark{s-\theseccount}\label{s-\theseccount}
\ifnum
  \getpagerefnumber{s-\theseccount}=\getpagerefnumber{e-\theseccount}\relax
  \begin{tikzpicture}[overlay, remember picture]
    \draw [line width=\mylinewidth,mycolor]
      ([xshift=-\linesep]\pos|-e-\theseccount) -- ([xshift=-\linesep]\pos|-s-\theseccount);
  \end{tikzpicture}%
\else
  \begin{tikzpicture}[overlay, remember picture]
    \draw [line width=\mylinewidth,mycolor]
      ([xshift=-\linesep]\pos) -- ([xshift=-\linesep]\pos|-s-\theseccount);
  \end{tikzpicture}%
\fi
}

\newcommand\Initrules{%
\begin{tikzpicture}[remember picture,overlay]
  \draw[line width=\mylinewidth,mycolor]
    ([xshift=\the\dimexpr\linesep\relax]current page text area.east|-e-1) --
    ([xshift=\linesep,yshift=-20pt]current page text area.east|-current page.north);
  \draw[line width=\mylinewidth,mycolor] 
    ([xshift=\the\dimexpr\linesep+0.5\mylinewidth\relax]current page text area.east|-e-1) --
    ([xshift=\the\dimexpr-\linesep-0.5\mylinewidth\relax]current page text area.west|-e-1);
\end{tikzpicture}%
}

\newcommand\tikzlinepage{%
\begin{tikzpicture}[overlay, remember picture]
  \draw [line width=\mylinewidth,mycolor]
    ([xshift=-\linesep]\pos) --
    ([xshift=-\linesep]\pos|-current page text area.south west);
\end{tikzpicture}
\addtocounter{linepages}{-1}%
\ifnum\value{linepages}>1
  \AtBeginShipoutNext{\tikzlinepage}%
\fi%
}

\AtBeginDocument{%
\noindent\tikzmark{s-0}
\StartSecLine
\Initrules}

\AtEndDocument{%
\EndSecLine}

\newcommand\StartMarks{\pretocmd{\section}{\EndSecLine\StartSecLine}{}{}}

\begin{document}

\section{Test Section One}
\lipsum[1-2]

\StartMarks

\section{Test Section Two}
\lipsum[1-8]
\section{Test Section Three}
\lipsum[4]
\section{Test Section Four}
\lipsum[1]
\section{Test Section Five}
\lipsum[4-5]
\section{Test Section Six}
\lipsum[4-6]

\end{document}

Changing the values for mycolor, \mylinewidth and \linesep, the color, width and separation between the rule and the text can be easily customized.

enter image description here

share|improve this answer
    
wow thank you very much! this looks very nice! what I initially wanted is a line that connects the upper right corner of the page with the right of the first section, and then the left of the first section to the left of the second, etc. so it would be sth like corner-|section 1 -|-section 2 etc (etc) sort of like a snake. I can do it in tikz manually, but i would like to do it automatically in every page. I realize it is too much to ask, so maybe if you could just tell me what to read on the subject. thanks again :) –  str. Nov 23 '12 at 14:41
4  
@GonzaloMedina: Woah! That's awesome! –  Jake Nov 23 '12 at 20:12
    
@Jake Thank you very much! I really appreciate your kind words! (I deleted my previous comment since the new updated code already supports multiple page breaks inside a section). –  Gonzalo Medina Nov 23 '12 at 20:55
    
@str. I updated my answer with a solution producing the zig-zag pattern. I hope something like this is what you needed. –  Gonzalo Medina Nov 24 '12 at 0:03
    
this is exactly what i wanted! thank you so very much! –  str. Nov 24 '12 at 10:05
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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