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 want to illustrate that the const in the following line can also be moved one word to the right. Maybe I can underline the const and draw a slim arced arrow pointing to the next gap?

const int * val
-----___-^

The TeX source is this:

\begin{auflistung} % itemize
  \itm{} % item
  \mono{\fett{const int} * val}
%...
\end{auflistung}

where auflistung serves as an itemize environment, itm as an item, mono as typewriter-tpye, and fett as bold.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

This can easily be done using pst-node - the node connection extension of pstricks. Here are a couple of examples:

\documentclass{article}
\usepackage{pst-node}% http://ctan.org/pkg/pst-node
\begin{document}
\begin{itemize}
  \item \texttt{\textbf{\rnode{A}{const} int}\rnode{B}{\strut\ }* val}
    \ncbar[nodesep=2pt,linewidth=0.5pt,angle=90]{->}{A}{B}

  \item \texttt{\textbf{\rnode{C}{const} int}\rnode{D}{\phantom{c}}* val}
    \nccurve[nodesep=2pt,linewidth=0.5pt,angleA=60,angleB=120]{->}{C}{D}

  \item \texttt{\textbf{\rnode{E}{const} int}\rlap{\rnode{F}{\phantom{oo}}} * val}
    \ncarc[nodesep=2pt,linewidth=0.5pt,arcangle=45]{->}{E}{F}

  \item \texttt{\textbf{\rnode{G}{const} int}\rnode{H}{\phantom{t}}* val}
    \ncdiag[nodesep=2pt,linewidth=0.5pt,arm=.3,linearc=.2,angle=90]{->}{G}{H}

\end{itemize}
\end{document}

Arrows used in code

Your compilation sequence is either latex -> dvips (-> ps2pdf) or xelatex. Modifications to the above code could include arrows/arcs spanning below the code (rather than above), colour, line style and width changes and many more. Read the pst-node documentation or the pstricks documentation (Chapter VII Nodes and Node Connections) for more information.

share|improve this answer
    
Beautiful! I had pst-node already installed on my system, so I used it. I have to deliver a .ps file, so I should be safe there, I guess. Currently I use ps2pdf and that works, too. I decided on \nccurve[linecolor=lightgray,nodesep=1pt,linewidth=0.5pt,angleA=40,angleB=140]{‌​->}{D}{W} –  towi Sep 27 '11 at 10:03
    
Also very good the hint about \phantom --- line 2 and line 3 --- I would not have known how to make perfectly matching spaces. –  towi Sep 27 '11 at 10:18
add comment

You could use TikZ for this.

Somewhere at the start of the document, issue

\tikzset{
    every picture/.style={
        remember picture,   % Make nodes available to all TikZ pictures
        inner xsep=0pt, % Remove horizontal padding
        inner ysep=1pt, % Set small vertical padding
        baseline,       % Align TikZ pictures at the baseline
        every node/.style={
            anchor=base % Align all nodes at the baseline
        }
    }
}

Then you can replace the word const with \tikz \node (a) {const}; and the space between int and * with \tikz \node (b) {\hphantom{ }};, creating two nodes (a) and (b) that can then be linked using \tikz [overlay] \draw [red,->] (a.south) to [bend right=70] (b.south);, yielding

Here's the complete document:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\tikzset{
    every picture/.style={
        remember picture,   % Make nodes available to all TikZ pictures
        inner xsep=0pt, % Remove horizontal padding
        inner ysep=1pt, % Set small vertical padding
        baseline,       % Align TikZ pictures at the baseline
        every node/.style={
            anchor=base % Align all nodes at the baseline
        }
    }
}


\begin{itemize} % itemize
  \item{} % item
  \texttt{\tikz \node [anchor=base]  (a) {const}; int\tikz \node  (b) {\hphantom{ }};* val}
    \tikz [overlay] \draw [red,->]  (a.south) to [bend right=70]  (b.south);
\end{itemize}

\end{document}
share|improve this answer
2  
Hehe, I also had TikZ in mind, but my solution was much less elegant. Fortunately one is informed about new answers being posted while typing ;) –  Tom Bombadil Sep 27 '11 at 6:21
    
I think I stumbled over tikz once. I have not used it, yet. –  towi Sep 27 '11 at 10:04
    
@jack, I use your code and compile it with xelatex or pdftexify twice, there is an error !missing \endcsname inserted. I ignore the error, then I can get your outcome. Hoe to solve it? thanks. –  Pig Cry Sep 27 '11 at 11:31
    
Now, 3 years later, that I wanted implement something similar. By now I am much more familiar with tikz and decided to go with your solution. And it works very well, thank you. –  towi Feb 16 at 12:20
add comment

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.