我创建了下一个新环境,在文档中插入 tikzfigure 的代码
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{minted}
\usepackage{tkz-fct}
\usetikzlibrary{babel, arrows, external, calc}
\usepackage{xcolor}
\definecolor{codeframe}{HTML}{2A7E43}
\definecolor{codeback}{HTML}{2B2E32}
\newenvironment{exampleTikz}
{\VerbatimEnvironment
\begin{VerbatimOut}{example.out}}
{\end{VerbatimOut}
\setlength{\parindent}{0pt}
\begin{minipage}{\textwidth}
\inputminted[
style = friendly,
fontsize=\footnotesize,
resetmargins,
frame = lines,
framesep = 2mm,
baselinestretch = 1.2,
bgcolor = codeback!15,
linenos
]{latex}{example.out}
\end{minipage}
\begin{figure}[ht]
\centering
\input{example.out}
\end{figure}
}
\begin{document}
\section{Un vector}
\begin{exampleTikz}
\begin{tikzpicture}[
scale = .75,
vector/.style = {>=latex, ->, line width = 1.5pt},
]
\tkzInit[xmin = -1, xmax = 4, ymin = -1, ymax = 4]
\tkzDrawXY[noticks]
\draw[vector] (0, 0) -- (2, 3);
\tkzPointShowCoord[xlabel = $2$, ylabel = $3$, color = gray!50](2, 3);
\end{tikzpicture}
\end{exampleTikz}
\end{document}
结果应该是
但我想将图形的标题作为参数传递,那么问题是,如何将图形的标题作为新环境的参数传递。
多谢。
答案1
以下方法可行:
\documentclass[]{article}
\newenvironment{mypicture}[2][]%
{%
\def\mypicturetemp{#2}%
\begin{figure}[#1]%
\centering%
}{%
\caption{\mypicturetemp}%
\end{figure}%
}
\begin{document}
\begin{mypicture}{foo}
\rule{1em}{1em}
\end{mypicture}
\end{document}
我使用了这个 MWE,因为您提供的代码无法在我的计算机上运行,因为它缺少\documentclass
和\usepackage
s。