답변1
빠른 첫 번째 접근 방식(패키지 제외 listings
):
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows, shapes.callouts}
\begin{document}
\begin{tikzpicture}[font=\ttfamily]
\foreach \x in {1,...,3} {
\node[fill=white, draw, drop shadow, align=left] at ({0.5*\x},{-0.5*\x}) (box \x) {
string reverseOf(string s) \{ \\
\quad\textcolor{magenta}{if} (s == "") \{ \\
\quad\quad\textcolor{magenta}{return} ""; \\
\quad\} \textcolor{magenta}{else} \{ \\
\quad\quad\textcolor{magenta}{return} reverseOf(s.substr(1)) + s[0]; \\
\quad\} \\
\}
};
\node[shape=rectangle callout, fill=black!10, draw, minimum width=3em, callout relative pointer={(-0.25,-0.25)}] at ([xshift=5pt, yshift=7.5pt]box \x.center) { "" };
\node[fill=black!10, draw=blue, anchor=south east, minimum width=3em, label={180:{string s}}] at ([xshift=-2pt, yshift=2pt]box \x.south east) { "p" };
}
\end{tikzpicture}
\end{document}
답변2
중독에@재스퍼 하비히트, 루프 에서 사용할 수 없기 때문에 글꼴( 또는 \usepackage{fontspec, inconsolata}
로 컴파일해야 함 )을 사용하여 코드와 비슷하게 만들 수 있습니다 (적어도 저는 사용할 수 없었습니다). 따라서 이를 가능한 한 이미지에 가깝게 만들기 위한 입력 및 출력은 다음과 같습니다.LuaTeX
XeLaTeX
\verb| |
\foreach
\documentclass[border = 1cm, 11pt]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{fontspec}
\usetikzlibrary{shapes.callouts, shadows}
\setmonofont{inconsolata}
\begin{document}
\begin{tikzpicture}[font = {\ttfamily}]
\foreach \i in {1,...,4} {
\node[
black,
align=left,
minimum width = 10.5 cm,
minimum height = 4 cm,
draw,
drop shadow={fill=black!100!white,shadow xshift=+2.4mm, shadow yshift=-2.4mm},
line width = 3pt,
fill=white,
inner xsep = 12pt,
] at ({0.7*\i},{-0.8*\i}) (thenode \i){%
string reverseOf(string s) \{ \\
\quad \textcolor{violet}{\textbf{if}} (s == "") \{ \\
\quad\quad\quad \textcolor{violet}{\textbf{return}} ""; \\
\quad \} \textcolor{violet}{\textbf{else}} \{ \\
\quad\quad\quad \textcolor{violet}{\textbf{return}} reverseOf(s.substr(1)) + s[0]; \\
\quad \} \\
\}
};
\node[
fill=blue!5!white,
draw=black,
anchor=south east,
minimum width=4em,
label={180:{string s}}
] at ([xshift=-7pt, yshift=7pt]thenode \i.south east) { "p" };
\node[%
shape=rectangle callout,
fill=black!10!white,
draw= black,
minimum width=5em,
rounded corners,
callout relative pointer={(-0.7,-0.45)}
] at ([xshift=27pt, yshift=9.7pt]thenode \i.center) {""};
}
\end{tikzpicture}
\end{document}