PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : TIKZ Übergabe von Optionen als Makro



msthab
18-12-2019, 07:58
Hallo,
ich möchte gerne bei TIKZ die (Skalierungs-) Optionen bei \begin{tikzpicture}[] als Makro übergeben, also z.B.:

\newcommand{\Skalierung}{xscale=0.3}
\begin{tikzpicture} [\Skalierung]

Funktioniert aber nicht.
Wie kann ich das Problem beheben?

Vielen Dank & Grüße

Manfred

Hier das Minimalbeispiel:


\documentclass{scrartcl}
\usepackage{tikz}
\begin{document}
Funktioniert:

\begin{tikzpicture} [xscale=0.3]
\draw (0,0) rectangle (5,5);
\end {tikzpicture}

Funktioniert nicht

\newcommand{\Skalierung}{xscale=0.3}
\begin{tikzpicture} [\Skalierung]
\draw (0,0) rectangle (5,5);
\end {tikzpicture}
\end{document

rais
18-12-2019, 22:38
Das Problem ist vermutlich, daß statt "opt"="val" so "opt=val" gesehen (und damit ungültig) wird.
Die eine oder andere Idee kann ich auch anbieten:


\documentclass{scrartcl}
\usepackage{tikz}
\newenvironment{foo}[1][]{%
\expandafter\tikzpicture\expandafter[#1]
}{%
\endtikzpicture
}

\begin{document}
Funktioniert:

\begin{tikzpicture} [xscale=0.3]
\draw (0,0) rectangle (5,5);
\end {tikzpicture}

Funktioniert auch:

\newcommand{\Skalierung}{xscale=0.3}
\begin{foo} [\Skalierung]
\draw (0,0) rectangle (5,5);
\end {foo}

Sowas geht auch:

\newcommand*\skalierung{0.3}
\begin{tikzpicture} [xscale=\skalierung]
\draw (0,0) rectangle (5,5);
\end {tikzpicture}

\end{document}

VG

msthab
23-12-2019, 15:43
Vielen Dank!
Die Lösung mit der newenvironment funktioniert prima!