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'm a very beginner in using circuitikz in my tex documents.

I'd like to obtain a label that shows both the part name and the component value. Looking in this forum I found this solution:

\documentclass{article}
\usepackage[siunitx]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,0) to  [R, l_={\parbox{1cm}{\centering R$_1$\\\SI{510}{\ohm}}}] (2,0);
\end{circuitikz}
\end{document}

The output is good but I'm not very satisfied by the code.

Is there any simpler/easier solution?

share|improve this question
1  
Welcome to TeX.SE. One way would be to define \newcommand*{\MyLabel}[3][1cm]{\parbox{#1}{\centering #2 \\ #3}}, and then use it as ` l_=\MyLabel{$R_1$}{\SI{510}{\ohm}}`. –  Peter Grill Aug 1 '12 at 18:25
    
Thank you for your answer! This is a good and simple solution! –  bersanri Aug 4 '12 at 8:26
add comment

1 Answer 1

up vote 5 down vote accepted

Here I provide a different solution from the one suggested by Peter.

Basically, I define a new kind of label lx that accepts two commands: the first one is the component name (for example R_1, C_1) and the second is dedicated to the component value. Its behaviour is similar to the standard l, therefore the followings:

  • lx_=...
  • lx^=...

hold. In conclusion, the command should be used as:

lx_={component_name and component_value}

For instance:

lx^={C$_1$ and \SI{1}{\farad}}

Here is the complete example:

\documentclass{article}
\usepackage[siunitx]{circuitikz}

\makeatletter
\ctikzset{lx/.code args={#1 and #2}{ 
  \pgfkeys{/tikz/circuitikz/bipole/label/name=\parbox{1cm}{\centering #1  \\ #2}}
    \ctikzsetvalof{bipole/label/unit}{}
    \ifpgf@circ@siunitx 
        \pgf@circ@handleSI{#2}
        \ifpgf@circ@siunitx@res 
            \edef\pgf@temp{\pgf@circ@handleSI@val}
            \pgfkeyslet{/tikz/circuitikz/bipole/label/name}{\pgf@temp}
            \edef\pgf@temp{\pgf@circ@handleSI@unit}
            \pgfkeyslet{/tikz/circuitikz/bipole/label/unit}{\pgf@temp}
        \else
        \fi
    \else
    \fi
}}

\ctikzset{lx^/.style args={#1 and #2}{ 
    lx=#2 and #1,
    \circuitikzbasekey/bipole/label/position=90 } 
}

\ctikzset{lx_/.style args={#1 and #2}{ 
    lx=#1 and #2,
    \circuitikzbasekey/bipole/label/position=-90 } 
}
\makeatother

\begin{document}
\begin{circuitikz}
\draw (0,-3) to  [R, lx_={R$_1$ and \SI{510}{\ohm}}] (2,-3);
\draw (6,-3) to  [C, lx^={C$_1$ and \SI{1}{\farad}}] (8,-3);
\end{circuitikz}
\end{document}

Result:

enter image description here

share|improve this answer
    
This is what I was looking for! I probably will use lx=#1 and #2, even with then lx^ command. Thank you! –  bersanri Aug 4 '12 at 8:24
    
Glad of having helped you. For lx^ I personally prefer this solution, but it's just an opinion. :) –  Claudio Fiandrino Aug 4 '12 at 11:55
add comment

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.