How to simplify a basic diagram
I think there are two different questions here and I am not sure which one is that you ask: One is how to draw the diagram efficiently I guess,
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x in {1,2,3,4} {
\draw (0.3*\x ,2mm) -- (0.3*\x,9mm)
node[above] {\pgfmathparse{2*\x-1}\pgfmathprintnumber{\pgfmathresult}}
(0.3*\x,-2mm) -- (0.3*\x,-9mm)
node[below] {\pgfmathparse{2*\x}\pgfmathprintnumber{\pgfmathresult}};
}
\draw (1.2cm,-2mm) -- ++(-3cm,0) (1.2cm,2mm) -- ++(-3cm,0);
\end{tikzpicture}
\end{document}
which gives
,
the other one is how to place this in a page (which is not so clear as a question). If you can provide more details about the page (is it a presentation or a plain article? do you want to wrap some text around it? Is it just a figure? etc.) that you are designing we can help further.
EDIT I hope I got it right but here it goes:
\begin{tikzpicture}
\begin{scope}%--- I just put the first picture in a scope
\foreach \x in {1,2,3,4} {
\draw (0.35*\x ,2mm) -- (0.35*\x,9mm)
node[above] {\pgfmathparse{2*\x-1}\pgfmathprintnumber{\pgfmathresult}}
(0.35*\x,-2mm) -- (0.35*\x,-9mm)
node[below] {\pgfmathparse{2*\x}\pgfmathprintnumber{\pgfmathresult}};
}
\draw (1.4cm,-2mm) -- ++(-3cm,0) (1.4cm,2mm) -- ++(-3cm,0);
\end{scope}
\begin{scope}[xshift=5cm]%--- This moves the contents of this scope to the right
\foreach \x in {1,2,...,10} {
\draw (0.35*\x ,2mm) -- (0.35*\x,9mm)
node[above] {\pgfmathparse{2*\x-1}\pgfmathprintnumber{\pgfmathresult}}
(0.35*\x,-2mm) -- (0.35*\x,-9mm)
node[below] {\pgfmathparse{2*\x}\pgfmathprintnumber{\pgfmathresult}};
}
\draw (3.5cm,-2mm) -- ++(-5cm,0) (3.5cm,2mm) -- ++(-5cm,0);
\end{scope}
% ground symbol does not require a scope anyway but convenient to place it
% since I am not sure if I got the idea correctly
\begin{scope}[xshift=2.5cm,yshift=-2cm]
\draw (0,0) -- (0,1) (-0.7,0)--(0.7,0);
\draw (-4.5mm,-3mm) -- (4.5mm,-3mm);
\draw (-2mm,-6mm) -- (2mm,-6mm);
\end{scope}
\end{tikzpicture}
I hope I am somewhere close to what you described in your edit.
Admittedly, this is a bit crude but hopefully it points you in the right direction. Basically, this sets up a TikZ to path style that lets you draw the diagram at any position in your TikZ picture. Using the center
, flushleft
, flushright
environments you should be able to put the picture in the right position in a figure
(assuming you're using a figure
environment ot present the picture).
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{my diagram/.style={to path={
(\tikztostart) coordinate (a) -- (\tikztotarget) coordinate (b)
($(a)!0.4cm!+90:(b)$) coordinate (a')
($(b)!0.4cm!-90:(a)$) coordinate (b')
\foreach \distance/\label in {0.0cm/1,0.2cm/3,0.4cm/5,0.6cm/7} {
($(b)!\distance!(a)$) coordinate (tmp) -- ($(tmp)!0.4cm!-90:(a)$)
node[allow upside down,anchor=south,pos=1,sloped,rotate=-90] {\label}
}
($(a)!0.2cm!-90:(b)$) coordinate (c)
($(b)!0.2cm!+90:(a)$) coordinate (d)
(c) -- (d)
($(c)!0.4cm!-90:(d)$) coordinate (c')
($(d)!0.4cm!+90:(c)$) coordinate (d')
\foreach \distance/\label in {0.0cm/2,0.2cm/4,0.4cm/6,0.6cm/8} {
($(d)!\distance!(c)$) coordinate (tmp) -- ($(tmp)!0.4cm!+90:(c)$)
node[allow upside down,anchor=north,pos=1,sloped,rotate=+90] {\label}
}}}}
\begin{tikzpicture}
\draw (0,0) to[my diagram] (1.5,0);
\draw (2,2) to[my diagram] (3.0,0);
\end{tikzpicture}
\end{document}
(source: ucc.ie)
run it with xelatex
or latex->dvips->ps2pdf
\documentclass{article}
\usepackage{pst-node}
\def\Node#1{\rnode{#1}{#1}}
\begin{document}
\pnode(0,-8mm){A}\hspace*{3cm}\Node{1}~\Node{3}~\Node{5}~\Node{7}
\psforeach{\iA}{1,3,5,7}{\ncangle[angleB=-90,nodesepB=2pt]{A}{\iA}}
\vspace{1.7cm}
\pnode(0,10mm){A}\hspace*{3cm}\Node{2}~\Node{4}~\Node{6}~\Node{8}
\psforeach{\iA}{2,4,6,8}{\ncangle[angleB=90,nodesepB=2pt]{A}{\iA}}
\end{document}