
在 Beamer 中,如果我們使用 tkzexample 套件來示範一些程式碼(請參閱這個例子),有時程式碼會跑出框架框。
- 如果程式碼行太長,是否可以使其自動換行?
- 第二張圖和第三張圖之間的距離似乎不相等。
範例程式碼:
\documentclass[t]{beamer}
\usepackage{tikz}
\usepackage{tkzexample}
\colorlet{graphicbackground}{red!10!white}%
\colorlet{codebackground}{blue!10!white}%
\colorlet{codeonlybackground}{blue!10!white}
\begin{document}
\begin{frame}[fragile]{tikz example}
\begin{tkzexample}[width=2cm]
\begin{tikzpicture}
\draw (0,0) node[circle,
shade,
ball color=orange,
minimum size=2cm]{};
\end{tikzpicture}
\end{tkzexample}
\begin{tkzltxexample}[line frame width=0pt]
\begin{tkzexample}[width=1cm]
\tikz[baseline]
\node [circle,line width=1ex,draw=blue,fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{tkzltxexample}
\begin{tkzexample}[width=1.7cm]
\tikz[baseline]
\node [circle,line width=1ex,draw=blue,fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{frame}
\end{document}
輸出:
答案1
如果你不介意改為tcolorbox
包包而不是tkzexample
你可以做類似的事情:
tcolorbox
使用listings
(或minted
) 進行程式碼排版,其所有選項(字型樣式、行編號、斷行...)都可以套用於清單部分。我看過了tkzexample
,我認為它沒有使用它。
目前我不知道如何為TiKZ
圖形添加背景顏色。我們會知道,更改text outside listing
但text side listing
在這種情況下,程式碼和結果框之間沒有分離。
\documentclass[t]{beamer}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\newtcblisting{tkzexample}[1][]{text outside listing, fonttitle=\bfseries, bicolor, colback=blue!10!white, colbacklower=red!10!white, colframe=black, sharp corners, frame hidden, size=tight, #1}
\newtcblisting{tkzltxexample}[1][]{listing only, fonttitle=\bfseries, bicolor, colback=blue!10!white,colbacklower=red!10!white, colframe=black, sharp corners, frame hidden, size=tight, #1}
\begin{document}
\begin{frame}[fragile]{tikz example}
\begin{tkzexample}[lefthand width=2cm]
\begin{tikzpicture}
\draw (0,0) node[circle,
shade,
ball color=orange,
minimum size=2cm]{};
\end{tikzpicture}
\end{tkzexample}
\begin{tkzltxexample}[listing only]
\begin{tkzexample}[width=1cm]
\tikz[baseline]
\node [circle, line width=1ex, draw=blue, fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{tkzltxexample}
%
\begin{tkzexample}[lefthand width=1.5cm]
\tikz[baseline]
\node [circle, line width=1ex, draw=blue, fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{frame}
\end{document}