I'm typesetting source code with the listings
package's lstlisting
environment. Since I have to draw custom stuff in some lines, I use escapeinside
in these lines to insert a tikzpicture
.
Since these lines may be indented, I need to know the length of the indentation, or the remaining width of the line. Is there any way to access that?
\linewidth
still contains the full line length, so a box of width \linewidth
sticks out on the right as much as the line was indented.
For example, consider this document:
\documentclass{article}
\usepackage{tikz}
\usepackage{listings}
\begin{document}
\newcommand{\mwebox}{\begin{tikzpicture}[baseline]\path[fill=black!10, draw=black!0, thick] (0,-0.20) rectangle (5, 0.30);\end{tikzpicture}}
\begin{lstlisting}[escapeinside=~~]
Test
~\mwebox~
Test
Test
~\mwebox~
Test
\end{lstlisting}
\end{document}
I want to extend the gray boxes to the end of the lines.
\documentclass
command, have a minimal preamble and then\begin{document}...\end{document}
. The code should compile and be as small as possible to demonstrate your problem. This makes it much easier for people to help you --- and much more likely that they will!