TeX - LaTeX Asked by T.Stammer on March 12, 2021
can someone tell me how to make the following picture in Latex?
Especially the box and the outer row count?
Thanks!
The documentation of the listing
package contains many examples. A starting point:
documentclass{article}
usepackage[scaled]{beramono}
usepackage[T1]{fontenc}
usepackage{listings}
lstset{frame=single,numbers=left,language=java,basicstyle=ttfamily,captionpos=b}
begin{document}
begin{lstlisting}[caption={Attribute der Klasse texttt{BankAccount}}]
class BankAccount {
String name;
Hamster hamster;
Integer grainNumber;
Integer maximumOverdraft;
[...]
}
end{lstlisting}
end{document}
Correct answer by campa on March 12, 2021
Here's a minted
+tcolorbox
approach. Peruse their documentation to change the aspect. Remember to run pdflatex
(or any other engine) with the -shell-escape
option. You also need pygmentize
on your system (it's a Python add-on).
documentclass{article}
usepackage[many]{tcolorbox}
tcbuselibrary{minted}
NewTCBListing{java}{O{}}
{
left=2pt,
minted language=java,
minted options={linenos,#1},
listing only,
}
begin{document}
begin{listing}[htp]
begin{java}
class BankAccount {
String name;
Hamster hamster;
Integer grainNumber;
Integer maximumOverdraft;
[...]
end{java}
caption{Attribute der Klasse texttt{BankAccount}label{bankaccount}}
end{listing}
end{document}
The environment has an optional argument to set, if needed, further minted
options.
If you're running a version of LaTeX prior to the 2020-10-01 release, you also need
usepackage{xparse}
Answered by egreg on March 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP