是否可以将 tex 代码列表做成圆角?鉴于:
\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{xcolor} %used for font color
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage{listings}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\begin{document}
\definecolor{lbcolor}{rgb}{0.1,0.1,0.1}
\lstdefinestyle{mystyle}{
basicstyle=\ttfamily\color{White},
language=Java,
tabsize=1,
keywordstyle=\color{Red}\bf,
showstringspaces=false,
morekeywords={public, class}
}
\newtcblisting{mylisting}{
arc=0pt,
top=0mm,
bottom=0mm,
left=0mm,
right=0mm,
boxrule=0pt,
colback=black,
listing only,
listing options={style=mystyle},
hbox
}
\begin{mylisting}
public class MyObject{
public MyObject(){
System.out.println("MyObject");
}
}
\end{mylisting}
\end{document}
我想制作一个圆角。此代码将包含在演示文稿中,虽然只是外观问题,但当您拥有漂亮的圆角和阴影时,它看起来会更有吸引力。可以在 Latex 中完成吗?
答案1
选项arc
就是为此目的提供的。您已将其设置为0pt
。更改其值以表示类似5mm
(例如)。此外,您可以使用enhanced
选项和skins
库添加阴影tcolorbox
。语法如下
shadow={<xshift>}{<yshift>}{<offset>}{<options>}
完整代码:
\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{xcolor} %used for font color
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage{listings}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins} %%% skins needed for shadow
\begin{document}
\definecolor{lbcolor}{rgb}{0.1,0.1,0.1}
\lstdefinestyle{mystyle}{
basicstyle=\ttfamily\color{White},
language=Java,
tabsize=1,
keywordstyle=\color{Red}\bf,
showstringspaces=false,
morekeywords={public, class}
}
\newtcblisting{mylisting}{
enhanced, %%% needed for shadow
arc=5mm,
top=0mm,
bottom=0mm,
left=0mm,
right=0mm,
boxrule=0pt,
colback=black,
shadow={5mm}{-3mm}{0mm}{fill=black!50!white,
opacity=0.5}, %%% here for shadow and adjust as you like
listing only,
listing options={style=mystyle},
hbox
}
\begin{mylisting}
public class MyObject{
public MyObject(){
System.out.println("MyObject");
}
}
\end{mylisting}
\end{document}
答案2
\documentclass{book}
\usepackage{listings}
\lstset{frameshape={RYR}{Y}{Y}{RYR}}
\begin{document}
\begin{lstlisting}[language=Python,breaklines,basicstyle=\footnotesize\ttfamily]{P04-Tk.py}
from tkinter import * # import Tkinter module
root = Tk() # create Tk root widget
root.mainloop() # enter Tkinter event loop
\end{lstlisting}
\end{document}
对于双线:\lstset{frameshape={ryrRYR}{yY}{yY}{ryrRYR}}