Graphics, Figures & Tablesdraw figure with Tikz

Information and discussion about graphics, figures & tables in LaTeX documents.
beningermany
Posts: 10
Joined: Tue Aug 21, 2018 5:55 pm

draw figure with Tikz

Post by beningermany »

Hi Stefan, Thank you very much for your great help and elegant codes.
since no knowledge of style and append after command,
I applied rotate 90 degree within the command of adding capacitors with node command
in order to get horizontal capacitor.

Code: Select all

\documentclass[tikz, border=10pt]{standalone}

%\usepackage{tikz}

\usetikzlibrary{positioning}
\makeatletter
\begin{document}
\begin{tikzpicture}[
    capacitor/.style  = {
        fill = white,
        inner sep = 0pt,
        minimum width  = 1mm, 
        minimum height = 2mm, 
        append after command =
          {  (\tikzlastnode.south west) edge[black] (\tikzlastnode.north west)
             (\tikzlastnode.south east) edge[black] (\tikzlastnode.north east)} }
  ]
  
  \def\height{5}
  \def\width{3}
  
  \draw (0, 0)   [red]          ellipse (\width cm and 1 cm);
  \draw (0,-\height )  [red] ellipse (\width cm and 1 cm);
  
  \foreach \i in { 1,...,8 } {
    \coordinate (top\i) at (45*\i+138:\width cm and 1cm);
    \coordinate [below = \height cm of top\i] (bottom\i);
    \coordinate (capacitor-top\i) at (45*\i+138:\width cm and 1cm);
    \coordinate [below = \height*0.5 cm of capacitor-top\i]
                (capacitor-bottom\i);
  }
  
  \foreach \i in { 1,...,5 }
    \draw [red](top\i) -- (bottom\i);  
  \foreach \i in { 6,...,8 }
    \draw [red][dashed] (top\i) -- (bottom\i);
    
  \foreach \i in { 1,...,8 } {
   % \node [capacitor]  at (capacitor-top\i) {};
          
    % \node [capacitor] at (capacitor-top\i) {};
          
   \node [capacitor] [rotate=90]  at (capacitor-bottom\i) {}; 
   % rotate 90 of the capacitor . 
  }
\end{tikzpicture}
\end{document}
Last edited by beningermany on Tue Aug 28, 2018 6:59 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10330
Joined: Mon Mar 10, 2008 9:44 pm

draw figure with Tikz

Post by Stefan Kottwitz »

Rotating is good. One could simple draw lines, but I prefer nodes since one can easily label and reference them.
Nice that it works.

Stefan
LaTeX.org admin
beningermany
Posts: 10
Joined: Tue Aug 21, 2018 5:55 pm

draw figure with Tikz

Post by beningermany »

Hi Stefan,
since learning from you how to draw the figures, I have realized how interesting and difficult it is in the field of scientific drawing. The concept of node is really powerful. I need learn and practice it.
Cheers
Ben
Post Reply