Globale "background opacity" - Markierungsbox tikz

Redefinition von Makros, Definition eigener Befehle sowie neuer Umgebungen


Kays1623
Forum-Newbie
Forum-Newbie
Beiträge: 2
Registriert: Di 9. Jul 2013, 12:17

Globale "background opacity" - Markierungsbox tikz

Beitrag von Kays1623 »

Hi,
ich habe mir einen Befehl für eine Markierungsbox mit Textfeld für eine tikzpicture-Umgebung gebastelt, welche ein Standardlayout beinhaltet, welches ich aber gegebenfalls anpassen kann. Entweder kann ich diese über die optionalen Parameter bei jeder "MarkBox" angeben oder für alle folgenden "MarkBoxes" mit dem Befehl "MarkBoxSet" ändern.

Das klappt soweit auch alles gut, mein einziges Problem ist, dass ich die "background opacity" nicht neudefinieren kann, da diese keine dimension besitzt und ich nicht herausfinden konnte, wie ich diese für ein gesamtes dokument/gesamte Umgebung ändern kann. Daher kann ich zwar bei jeder "MarkBox" die background opacity ändern, aber nicht über den "MarkBoxSet"-Befehl. Kann mir jemand sagen wie ich diese in den "MarkBoxSet"-Befehl einbauen kann? Und was zwar nicht ganz so wichtig ist, aber auch noch fehlt ist, wie ich über den "MarkBoxSet"-Befehl die optionen "draw" und "line width" übergeben könnte.

Das "minimal"-Beispiel müsste komplett kompilierbar sein, hoffe ich habe das soweit richtig gemacht, ist ja mein erster post ;)

Wahrscheinlich könnte man die beiden Befehle anders viel besser definieren, als ich das getan habe, aber mit meinem Wissen über LaTeX ist mir das noch nicht möglich. :oops:

Danke schon mal für mögliche Antworten und Hilfestellungen. :)

\documentclass{article}
\usepackage[table,usenames,dvipsnames]{xcolor}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{keycommand}
\definecolor{backgroundcolor}{named}{red}
\definecolor{bordercolor}{named}{red}
\definecolor{backgroundtextcolor}{named}{red}
\definecolor{textcolor}{named}{white}
\newdimen\xshift
\xshift=0pt 
\newdimen\yshift
\yshift=0pt 
\newdimen\shift
\shift=0pt 
\newkeycommand\MarkBoxSet[draw=,line=thick,border color=bordercolor,background color=backgroundcolor,background text color=backgroundtextcolor,text color=textcolor,xshift=\xshift,yshift=\yshift,shift=\shift]{
\definecolor{backgroundcolor}{named}{\getcommandkey{background color}} 
\definecolor{bordercolor}{named}{\getcommandkey{border color}}
\definecolor{backgroundtextcolor}{named}{\getcommandkey{background text color}}
\definecolor{textcolor}{named}{\getcommandkey{text color}}
\yshift=\getcommandkey{yshift}
\xshift=\getcommandkey{xshift}
\shift=\getcommandkey{shift}
}
\newkeycommand\MarkBox[draw=,line=ultra thick,border color=bordercolor,background color=backgroundcolor,background text color=backgroundtextcolor,background opacity=0.2,background text opacity =0.8,text color=textcolor,xshift=\xshift,yshift=\yshift,shift=\shift][7]{
\ifthenelse{\equal{#1}{inside}}{
\ifthenelse{\equal{#2}{bottom left}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=south west, xshift=\getcommandkey{xshift}, yshift=\getcommandkey{shift}] at (#3,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{bottom right}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=south east, xshift=\getcommandkey{xshift}, yshift=\getcommandkey{shift}] at (#5,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{top left}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=north west, xshift=\getcommandkey{xshift}, yshift=-\getcommandkey{shift}] at (#3,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{top right}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=north east, xshift=\getcommandkey{xshift}, yshift=-\getcommandkey{shift}] at (#5,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{left bottom}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=south west, xshift=\getcommandkey{shift}, yshift=\getcommandkey{yshift}] at (#3,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{right bottom}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=south east, xshift=-\getcommandkey{shift}, yshift=\getcommandkey{yshift}] at (#5,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{left top}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=north west, xshift=\getcommandkey{shift}, yshift=\getcommandkey{yshift}] at (#3,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{right top}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=north east, xshift=-\getcommandkey{shift}, yshift=\getcommandkey{yshift}] at (#5,#4) {\vphantom{g}#7};}{\empty}
}{\empty}
\ifthenelse{\equal{#1}{outside}}{
\ifthenelse{\equal{#2}{bottom left}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=south east, xshift=\getcommandkey{xshift}, yshift=\getcommandkey{shift}] at (#3,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{bottom right}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=south west, xshift=\getcommandkey{xshift}, yshift=\getcommandkey{shift}] at (#5,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{top left}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=north east, xshift=\getcommandkey{xshift}, yshift=-\getcommandkey{shift}] at (#3,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{top right}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=north west, xshift=\getcommandkey{xshift}, yshift=-\getcommandkey{shift}] at (#5,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{left bottom}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=north west, xshift=\getcommandkey{shift}, yshift=\getcommandkey{yshift}] at (#3,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{right bottom}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=north east, xshift=-\getcommandkey{shift}, yshift=\getcommandkey{yshift}] at (#5,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{left top}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=south west, xshift=\getcommandkey{shift}, yshift=\getcommandkey{yshift}] at (#3,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{right top}}
{
\draw [\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background color},fill opacity=\getcommandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\getcommandkey{draw},\getcommandkey{line},color=\getcommandkey{border color}, fill=\getcommandkey{background text color}, fill opacity=\getcommandkey{background text opacity}, text opacity=1,text=\getcommandkey{text color},anchor=south east, xshift=-\getcommandkey{shift}, yshift=\getcommandkey{yshift}] at (#5,#4) {\vphantom{g}#7};}{\empty}
}{\empty}
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\MarkBox{outside}{top left}{-2}{2}{2}{-2}{text}
\end{tikzpicture}
\caption{A}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\MarkBoxSet[background color=green, background text color=yellow, text color=blue]
\MarkBox{outside}{top left}{-2}{2}{2}{-2}{text}
\end{tikzpicture}
\caption{B}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\MarkBoxSet[background color=green, background text color=yellow, text color=blue]
\MarkBox[background opacity=0.6]{outside}{top left}{-2}{2}{2}{-2}{text}
\end{tikzpicture}
\caption{C}
\end{figure}
\end{document}
[\code]

Benutzeravatar
Stefan Kottwitz
Admin
Admin
Beiträge: 2759
Registriert: Di 8. Jul 2008, 00:39
Kontaktdaten:

Beitrag von Stefan Kottwitz »

Willkommen im Forum!

Das ist soviel und sehr oft wiederholter Code, am besten fasse doch einfach mal gleiche Bestandteile zusammen, indem Du Dir ein Makro mit \newcommand definierst. Wenn das dadurch übersichtlicher und kürzer geworden ist, lässt sich auch besser helfen.

Stefan

Noch so einer

Beitrag von Noch so einer »

Zunächst einmal verstehe ich nicht, warum du \getcomandkey an Stelle von \commandkey verwendest. Mit \commandkey ist das nämlich eigentlich recht einfach:
\documentclass{article}
\usepackage[table,usenames,dvipsnames]{xcolor}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{keycommand}
\definecolor{backgroundcolor}{named}{red}
\definecolor{bordercolor}{named}{red}
\definecolor{backgroundtextcolor}{named}{red}
\definecolor{textcolor}{named}{white}
\newdimen\xshift
\xshift=0pt
\newdimen\yshift
\yshift=0pt
\newdimen\shift
\shift=0pt
\newcommand*\backgroundopacity{0.2}
\newkeycommand\MarkBoxSet[draw=,line=thick,border color=bordercolor,background
color=backgroundcolor,background text color=backgroundtextcolor,text
color=textcolor,xshift=\xshift,yshift=\yshift,shift=\shift,background opacity=\backgroundopacity]{
\definecolor{backgroundcolor}{named}{\commandkey{background color}}
\definecolor{bordercolor}{named}{\commandkey{border color}}
\definecolor{backgroundtextcolor}{named}{\commandkey{background text color}}
\definecolor{textcolor}{named}{\commandkey{text color}}
\yshift=\commandkey{yshift}
\xshift=\commandkey{xshift}
\shift=\commandkey{shift}
\xdef\backgroundopacity{\commandkey{background opacity}}
}
\newkeycommand\MarkBox[draw=,line=ultra thick,border color=bordercolor,background color=backgroundcolor,background text color=backgroundtextcolor,background opacity=\backgroundopacity,background text opacity =0.8,text color=textcolor,xshift=\xshift,yshift=\yshift,shift=\shift][7]{
\ifthenelse{\equal{#1}{inside}}{
\ifthenelse{\equal{#2}{bottom left}}
{
\draw [\commandkey{line},color=\commandkey{border color},
fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=south west, xshift=\commandkey{xshift}, yshift=\commandkey{shift}] at (#3,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{bottom right}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=south east, xshift=\commandkey{xshift}, yshift=\commandkey{shift}] at (#5,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{top left}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=north west, xshift=\commandkey{xshift}, yshift=-\commandkey{shift}] at (#3,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{top right}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=north east, xshift=\commandkey{xshift}, yshift=-\commandkey{shift}] at (#5,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{left bottom}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=south west, xshift=\commandkey{shift}, yshift=\commandkey{yshift}] at (#3,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{right bottom}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=south east, xshift=-\commandkey{shift}, yshift=\commandkey{yshift}] at (#5,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{left top}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=north west, xshift=\commandkey{shift}, yshift=\commandkey{yshift}] at (#3,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{right top}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=north east, xshift=-\commandkey{shift}, yshift=\commandkey{yshift}] at (#5,#4) {\vphantom{g}#7};}{\empty}
}{\empty}
\ifthenelse{\equal{#1}{outside}}{
\ifthenelse{\equal{#2}{bottom left}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=south east, xshift=\commandkey{xshift}, yshift=\commandkey{shift}] at (#3,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{bottom right}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=south west, xshift=\commandkey{xshift}, yshift=\commandkey{shift}] at (#5,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{top left}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=north east, xshift=\commandkey{xshift}, yshift=-\commandkey{shift}] at (#3,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{top right}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=north west, xshift=\commandkey{xshift}, yshift=-\commandkey{shift}] at (#5,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{left bottom}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=north west, xshift=\commandkey{shift}, yshift=\commandkey{yshift}] at (#3,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{right bottom}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=north east, xshift=-\commandkey{shift}, yshift=\commandkey{yshift}] at (#5,#6) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{left top}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=south west, xshift=\commandkey{shift}, yshift=\commandkey{yshift}] at (#3,#4) {\vphantom{g}#7};}{\empty}
\ifthenelse{\equal{#2}{right top}}
{
\draw [\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background color},fill opacity=\commandkey{background opacity}](#3,#4) rectangle  (#5,#6); %
\node[font=\sffamily,rectangle,\commandkey{draw},\commandkey{line},color=\commandkey{border color}, fill=\commandkey{background text color}, fill opacity=\commandkey{background text opacity}, text opacity=1,text=\commandkey{text color},anchor=south east, xshift=-\commandkey{shift}, yshift=\commandkey{yshift}] at (#5,#4) {\vphantom{g}#7};}{\empty}
}{\empty}
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\MarkBox{outside}{top left}{-2}{2}{2}{-2}{text}
\end{tikzpicture}
\caption{A}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\MarkBoxSet[background color=green, background text color=yellow, text color=blue]
\MarkBox{outside}{top left}{-2}{2}{2}{-2}{text}
\end{tikzpicture}
\caption{B}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\MarkBoxSet[background color=green, background text color=yellow, text
color=blue, background opacity=0.6]
\MarkBox{outside}{top left}{-2}{2}{2}{-2}{text}
\end{tikzpicture}
\caption{C}
\end{figure}
\end{document}
Das setzt natürlich voraus, dass ich verstanden habe, was Du möchtest. Dessen bin ich mir nicht ganz sicher.

Kays1623
Forum-Newbie
Forum-Newbie
Beiträge: 2
Registriert: Di 9. Jul 2013, 12:17

Beitrag von Kays1623 »

Genau das was ich wollte :)

Vielen Dank dafür.

Worin liegt denn genau der Unterschied zwischen \commandkey und \getcommandkey?

Noch so einer

Beitrag von Noch so einer »

\getcommandkey ist AFAIK für die +-Variante vorgesehen und expandiert nicht AFAIK nicht vollständig. Die tikz-Eigenschaften funktionieren dann teilweise nicht richtig. Ich habe mich aber schlicht am Beispiel in der keycommand-Anleitung orientiert, das ebenfalls \commandkey verwendet.

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Hallo,

hier ist mal noch ein Vorschlag ohne das Paket keycommand. Allerdings müssen hier im zweiten Argument von \MarkBox die üblichen Anker von noden verwendet werden, also zum Bespiel west statt left:
\documentclass[parskip=full-]{scrartcl}

\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{ifthen}
\tikzset{%
     background color/.style=#1, 
       background color/.default=red, 
       background color/.estore in=\backgroundcolor, 
     border color/.style={color=#1}, 
       border color/.default=red, 
     background text color/.style=#1, 
       background text color/.default=red, 
       background text color/.estore in=\backgroundtextcolor, 
     text color/.style={text=#1}, 
       text color/.default=white, 
     background opacity/.style=#1, 
       background opacity/.default=0.2, 
       background opacity/.estore in=\backgroundopacity, 
     background text opacity/.style=#1, 
       background text opacity/.default=0.8, 
       background text opacity/.estore in=\backgroundtextopacity, 
     xshift/.estore in=\xshift, 
     yshift/.estore in=\yshift 
  }


\tikzset{
  markbox background/.style={
    border color, background color, background opacity, ultra thick,inner sep=0pt,draw},
%
  markbox text/.style={
    text color, background text color, background text opacity,
    font=\sffamily,ultra thick,outer sep=0pt,
    xshift=0pt,yshift=0pt,anchor=center},
%
  markboxset/.style={}
}
\newcommand\MarkBoxSet[1][]{\tikzset{markboxset/.append style={#1}}}

\newcommand\MarkBox[7]{%
% Festlegen des anchors für die Textbox
  \ifthenelse{\equal{#1}{inside}}{%
    \tikzset{markbox text/.append style={anchor=#2}}%
  }{%
    \ifthenelse{\equal{#1}{outside}}{%
      \ifthenelse{\equal{#2}{north east}}{%
          \tikzset{markbox text/.append style={anchor=north west}}}{}
      \ifthenelse{\equal{#2}{north west}}{%
          \tikzset{markbox text/.append style={anchor=north east}}}{}
      \ifthenelse{\equal{#2}{south east}}{%
          \tikzset{markbox text/.append style={anchor=south west}}}{}
      \ifthenelse{\equal{#2}{south west}}{%
          \tikzset{markbox text/.append style={anchor=south east}}}{}
      \ifthenelse{\equal{#2}{north}}{%
          \tikzset{markbox text/.append style={anchor=south}}}{}
      \ifthenelse{\equal{#2}{south}}{%
          \tikzset{markbox text/.append style={anchor=north}}}{}
      \ifthenelse{\equal{#2}{east}}{%
          \tikzset{markbox text/.append style={anchor=west}}}{}
      \ifthenelse{\equal{#2}{west}}{%
          \tikzset{markbox text/.append style={anchor=east}}}{}
    }%
    {}
}
% Zeichnen der Box
  \coordinate(h1)at(#3,#4);
  \coordinate(h2)at(#5,#6);
  \node[markbox background,markboxset,
    fill=\backgroundcolor,fill opacity=\backgroundopacity,
    fit=(h1) (h2),align=none](markbox){};
  \node[markbox text,markboxset,
    fill=\backgroundtextcolor,fill opacity=\backgroundtextopacity]
    at([shift={(\xshift,\yshift)}]markbox.#2){\strut #7 };
}

\begin{document} 

\begin{tikzpicture} 
  \MarkBox{outside}{north west}{-2}{2}{2}{-2}{text} 
\end{tikzpicture} 

\begin{tikzpicture} 
  \MarkBoxSet[background color=green, background text color=yellow, text color=blue,
              rounded corners,dashed] 
  \MarkBox{outside}{north west}{-2}{2}{2}{-2}{text} 
\end{tikzpicture} 
 
\begin{tikzpicture} 
  \MarkBoxSet[background color=green, background opacity=0.6,%
              background text color=yellow, text color=blue,
              xshift=-\pgflinewidth,yshift=-\pgflinewidth] 
\MarkBox{inside}{east}{-2}{2}{2}{-2}{text} 
\end{tikzpicture} 

\end{document}
Gruß
Elke

Antworten