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.
Here's one option:
listingspackage was used to typeset the code. The package offers additional customization possibilities for typesetting code; please refer to the documentation
TikZwas used here. The
tikzmarklibrary was used to place some marks (the
listingswas used to place the marks inside
lstlisting). Then those marks were used to draw the arrows and place the explanatory texts using
overlayoption has to be used in the
tikzpicturefor 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.