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 have to draw following circuit enter image description here the LaTeX source of which is

\documentclass{beamer}
\usepackage{circuitikz}
\begin{document}
\begin{frame}
\begin{figure}
\centering
\begin{circuitikz} \draw
(0,0) node[not port] (not1) {}
(0,2) node[xor port] (xor1) {}
(0,4) node[and port] (and1) {}
(2,3) node[nor port] (nor1) {}
(4,2) node[xor port] (xor2) {}
(6,3) node[or port] (or1) {}
(6,1) node[and port] (and2) {}
(nor1.in 1) node[above](f) {U}
(nor1.in 2) node[below](g) {U}
(xor2.in 1) node[above](h) {U}
(xor2.in 2) node[below](i) {U}
(or1.out) node[right](j) {U}
(and1.out) -- (nor1.in 1)
(xor1.out) -- (nor1.in 2)
(nor1.out) -- (xor2.in 1)
(not1.out) -- (xor2.in 2)
(and1.out) -- (or1.in 1)
(xor2.out) -- (or1.in 2)
(xor1.out) -- (and2.in 1)
(not1.out) -- (and2.in 2);
\end{circuitikz}
\end{figure}
\end{frame}
\end{document}

The circuit looks clumsy. What I want is that the gates whose inputs have been labelled U are drawn below the circuit such that the inputs wires of these circuits go downwards and then their outputs go upwards to the respective inputs.

The main question which I want to ask (which is also the title) is how to color the input and output wires of these gates red. By these gates I mean the gates whose inputs have been labelled U.

Will be very thankful even if slight help is offered.

share|improve this question

2 Answers 2

up vote 11 down vote accepted
+100

The diagram would be improved alot by using connecting wires that are only horizontal or vertical. There is a conveient syntax |- for a path that is first vertical then horizontal, and the corresponding -|. You can apply colours to the individual symbols and to the connecting wires by specifying color=red. Perhaps this is close to what you are after:

Sample output

\documentclass{beamer}
\usepackage{circuitikz}
\begin{document}
\begin{frame}
\begin{figure}
\centering
\begin{circuitikz} \draw
(0,0) node[not port] (not1) {}
(0,2) node[xor port] (xor1) {}
(0,4) node[and port] (and1) {}
(2,3) node[nor port,color=red] (nor1) {}
(4,1) node[xor port,color=red] (xor2) {}
(6,3) node[or port,color=red] (or1) {}
(6,1) node[and port] (and2) {}
(nor1.in 1) node[above](f) {U}
(nor1.in 2) node[below](g) {U}
(xor2.in 1) node[left](h) {U}
(xor2.in 2) node[left](i) {U}
(or1.out) node[right](j) {U};
\draw[color=red] (and1.out) |- (nor1.in 1)
(xor1.out) |- (nor1.in 2)
(nor1.out) -| (xor2.in 1)
(not1.out) -| (xor2.in 2)
(xor2.out) |- (or1.in 2);
\draw 
(and1.out) -- +(4,0) |- (or1.in 1)
(xor1.out) -| (and2.in 1)
(not1.out) -| (and2.in 2);
\end{circuitikz}
\end{figure}
\end{frame}
\end{document}

As the symbols are one unit, you can not (easily) change the colour an input wire right up to the symbol body.

share|improve this answer
1  
Dear Friend, How can I show my gratitude! Thanks a lot. If possible would have given 100 bounty points, which is all I have. –  kamalbanga May 1 at 14:04
    
@kamalbanga after a few days, your question will be eligible for a bounty :) –  cmhughes May 1 at 15:14
    
@cmhughes I will never be using LaTeX after a few days since my student life ends in two days. So I better use up my points. :) –  kamalbanga May 1 at 15:19
    
Comments should not be used for discussions, but in that code you link to change (xor2.out) -| (not2.in) to (xor2.out) |- (not2.in) –  Andrew Swann May 1 at 15:55
    
Oh, silly mistake. Got it. –  kamalbanga May 1 at 15:57

Here is a solution with the circuit libraries of TikZ. We need the extra -|- and |-| styles from Vertical and horizontal lines in pgf-tikz because the elements from circuits.logic... don't have pins.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{
  circuits,
  circuits.logic.IEC,
  circuits.logic.US,
  circuits.logic.CDH,
  calc
}
\tikzset{
  -|-/.style={
    to path={
      (\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget)
      \tikztonodes
    }
  },
  -|-/.default=0.5,
  |-|/.style={
    to path={
      (\tikztostart) |- ($(\tikztostart)!#1!(\tikztotarget)$) -| (\tikztotarget)
      \tikztonodes
    }
  },
  |-|/.default=0.5,
}
\begin{document}
\newcommand\pic[1][circuit logic IEC]{
  \begin{tikzpicture}[#1]
    \draw
    (0,0) node[not gate] (not1) {}
    (0,2) node[xor gate] (xor1) {}
    (0,4) node[and gate] (and1) {}
    (2,3) node[red,nor gate] (nor1) {}
    (4,2) node[red,xor gate] (xor2) {}
    (6,3) node[red,or gate] (or1) {}
    (6,1) node[and gate] (and2) {};
    \draw[red]
    (and1.output) to[-|-] (nor1.input 1) node[above left] {U}
    (xor1.output) to[-|-] (nor1.input 2) node[below left] {U}
    (nor1.output) to[-|-] (xor2.input 1) node[above left] {U}
    (not1.output) to[-|-] (xor2.input 2) node[below left] {U}
    (xor2.output) to[-|-] (or1.input 2)
    (or1.output) node[right] {U};
    \draw
    (and1.output) to[-|-] (or1.input 1)
    (xor1.output) to[-|-] (and2.input 1)
    (not1.output) to[-|-] (and2.input 2);
  \end{tikzpicture}
}
\begin{frame}{circuit logic IEC}
  \begin{figure}
    \centering
    \pic
  \end{figure}
\end{frame}
\begin{frame}{circuit logic US}
  \begin{figure}
    \centering
    \pic[circuit logic US]
  \end{figure}
\end{frame}
\begin{frame}{circuit logic CDH}
  \begin{figure}
    \centering
    \pic[circuit logic CDH]
  \end{figure}
\end{frame}
\end{document}

enter image description here enter image description here 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.