Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a new command with some default TikZ options that you can override using an optional argument. If working as intended the code below would generate a red line between A and B, and a translucent green line with arrows between A and C. How can I accomplish this?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\newcommand{\relation}[3][]
{
  % this needed to be modified somehow...
  \path [draw, red] (#2) -- (#3);
}

\begin{tikzpicture}
  \node [draw] (A) at (0, 0) {A};
  \node [draw] (B) at (3, 0) {B};
  \node [draw] (C) at (3, 3) {C};
  \relation{A}{B}
  \relation[<->, color=green!10]{A}{C}
\end{tikzpicture}

\end{document}
share|improve this question
1  
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  texenthusiast Jul 12 '13 at 4:56
4  
You already have the solution. Put draw,red,#1 and it's good to go. However, it is better to use draw=red such that you can easily override it with draw=none without having the red color set for fill etc. –  percusse Jul 12 '13 at 5:25

1 Answer 1

up vote 4 down vote accepted

As @TomBombadil answered in this question a way to do that is

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\CloudRed}[2][180]% [angle], content
{   \begin{tikzpicture}[overlay]
    \node[align=center, draw,  fill=red, text=white, cloud callout, cloud puffs=17, cloud puff arc=140, callout pointer segments=3, anchor=pointer, callout relative pointer={(#1:2 cm )}, aspect=4,scale=0.5] at (-3ex,0.5ex) {#2};
\end{tikzpicture}
}

\begin{document}

  \begin{itemize}
        \item XY Resistive MM\Cloud{Thank you Rui}
    \item Manufactured by Rui de Oliveira\Cloud[160]{Thanks again}
    \item bla bla bla\Cloud[120]{Thanks yet another time}
    \end{itemize}
\end{document}

The result looks like

enter image description here

As @percusse suggested just a little modification is needed to your code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\newcommand{\relation}[3][]
{
  % this needed to be modified somehow...
  \path [draw=red,#1] (#2) -- (#3);
}

\begin{tikzpicture}
  \node [draw] (A) at (0, 0) {A};
  \node [draw] (B) at (3, 0) {B};
  \node [draw] (C) at (3, 3) {C};
  \relation{A}{B}
  \relation[<->, color=green!40!black!100]{A}{C}
\end{tikzpicture}

\end{document}

The result is

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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