LaTeX forum ⇒ 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

Postby beningermany » Tue Aug 28, 2018 6:50 pm

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.

  1. \documentclass[tikz, border=10pt]{standalone}
  2.  
  3. %\usepackage{tikz}
  4.  
  5. \usetikzlibrary{positioning}
  6. \makeatletter
  7. \begin{document}
  8. \begin{tikzpicture}[
  9. capacitor/.style = {
  10. fill = white,
  11. inner sep = 0pt,
  12. minimum width = 1mm,
  13. minimum height = 2mm,
  14. append after command =
  15. { (\tikzlastnode.south west) edge[black] (\tikzlastnode.north west)
  16. (\tikzlastnode.south east) edge[black] (\tikzlastnode.north east)} }
  17. ]
  18.  
  19. \def\height{5}
  20. \def\width{3}
  21.  
  22. \draw (0, 0) [red] ellipse (\width cm and 1 cm);
  23. \draw (0,-\height ) [red] ellipse (\width cm and 1 cm);
  24.  
  25. \foreach \i in { 1,...,8 } {
  26. \coordinate (top\i) at (45*\i+138:\width cm and 1cm);
  27. \coordinate [below = \height cm of top\i] (bottom\i);
  28. \coordinate (capacitor-top\i) at (45*\i+138:\width cm and 1cm);
  29. \coordinate [below = \height*0.5 cm of capacitor-top\i]
  30. (capacitor-bottom\i);
  31. }
  32.  
  33. \foreach \i in { 1,...,5 }
  34. \draw [red](top\i) -- (bottom\i);
  35. \foreach \i in { 6,...,8 }
  36. \draw [red][dashed] (top\i) -- (bottom\i);
  37.  
  38. \foreach \i in { 1,...,8 } {
  39. % \node [capacitor] at (capacitor-top\i) {};
  40.  
  41. % \node [capacitor] at (capacitor-top\i) {};
  42.  
  43. \node [capacitor] [rotate=90] at (capacitor-bottom\i) {};
  44. % rotate 90 of the capacitor .
  45. }
  46. \end{tikzpicture}
  47. \end{document}
Attachments
low.png
low.png (36.72 KiB) Viewed 158 times
Last edited by beningermany on Tue Aug 28, 2018 6:59 pm, edited 1 time in total.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9192
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue Aug 28, 2018 7:08 pm

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
Site admin

beningermany
Posts: 10
Joined: Tue Aug 21, 2018 5:55 pm

Postby beningermany » Tue Aug 28, 2018 7:47 pm

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


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Baidu [Spider] and 8 guests