Eu tenho um código para o qual estou usando
\begin{lstlisting}
line1
line2
line3
\end{lstlisting}
Quero mostrar a linha1 e a linha3 inclinadas. Como isso pode ser feito ?
Responder1
Você pode usar delimitadores:
\documentclass{article}
\usepackage{listings}
\lstdefinestyle{mystyle}{
basicstyle = \ttfamily ,
moredelim = [is][\itshape]{|}{|}
}
\begin{document}
\begin{lstlisting}[style=mystyle]
|line1
line2|
line3
\end{lstlisting}
\end{document}
\begin{lstlisting}[style=mystyle]
|line1|
line2
|line3|
\end{lstlisting}
Responder2
Dependendo das complexidades, pode-se usar o argumento opcional dos verbatimbox
ambientes para conseguir isso:
\documentclass{article}
\usepackage{verbatimbox,xcolor}
\begin{document}
\newcommand\formatting{%
\ifnum\theVerbboxLineNo=1\relax\slshape\fi%
\ifnum\theVerbboxLineNo=3\relax\slshape\fi%
}
\begin{verbbox}[\formatting]
line1
line2
line3
\end{verbbox}
This is my code: \fbox{\theverbbox}
\renewcommand\formatting{%
\ifnum\theVerbboxLineNo=1\relax\slshape\fi%
\ifnum\theVerbboxLineNo=3\itshape\leavevmode%
\smash{\rlap{\color{red!20}\rule[-\dp\strutbox]{27pt}{\baselineskip}}}\fi%
}
\begin{verbbox}[\formatting]
line1
line2
line3
line4
\end{verbbox}
This is my revised code: \fbox{\theverbbox}
\end{document}