I have been searching for an answer for some time but have not come across a solution. I am taking some notes from a programming course and need to take a line of code and identify each individual part with alternating arrows. For example, the line:
this.Something = new AnotherThing(anArgument);
Now, I need an arrow below this line pointing up to 'this' coming from some text identifying the part. Now, another arrow would need to start at some explanation text above this line and point down to the 'Something'. The =, new, and parenthesis do not need anything, just the other items. I have been trying to use \underset and \overset, but the spacing on the line goes wonky. Any guidance will be greatly appreciated.
Best Answer
Here's one option:
The code:
Remarks
The
listings
package was used to typeset the code. The package offers additional customization possibilities for typesetting code; please refer to the documentationTikZ
was used here. Thetikzmark
library was used to place some marks (theescapeinside
feature fromlistings
was used to place the marks insidelstlisting
). Then those marks were used to draw the arrows and place the explanatory texts using\node
s.Since the
overlay
option has to be used in thetikzpicture
for the exaplanatory texts, some spacing will need to be added to get the proper spacing with the material surrounding the code.Some internal calculations are involved, so the code needs two runs to stabilize.