1

I make a next newenvironment to insert the code of a tikzfigure in the document

\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}

The result should be

enter image description here

but I want pass as an argument the caption to the figure, then the question is, how I can pass the caption of the figure as an argument of the newenvitonment.

Thanks a lot.

  • @Skillmon - I'm always happy to upvote a working answer. :-) – Mico Sep 2 '17 at 9:18
2

The following approach can work:

\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}

I used this MWE since your provided code can't be run on my machine, since it lacks the \documentclass and \usepackages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.