3

How drawing attache figure by Tikz?

\documentclass[a4paper]{book}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[line width = .6pt,font=\footnotesize]
\draw[->] (-1,0) -- (6,0) node[right,below]{$x$};
\draw[->] (0,-1) -- (0,4) node[above,left]{$y$};
\node at (-.2,-.2) {$O$};
\draw[line width =1pt] (.25,.5) .. controls (1.5,-1.5) and (1.5,.5) .. (3.75,3);
\draw (.5,.25) node[above]{$A$} -- (.5,-1);
\draw (1.5,-.5) node[above]{$B$} -- (1.5,-1);
\draw (2.5,.5) node[above]{$C$} -- (2.5,-1);
\draw (3.5,2.5) node[above]{$D$} -- (3.5,-1);
\draw (4.5,1.5) node[above]{$E$} -- (4.5,-1);
\end{tikzpicture}
\end{document}

enter image description here

3

If you name the five nodes a, b, etc., then you can use

\draw [shorten <=-5mm, shorten >=-5mm] plot [smooth] coordinates {(a.south)(b.south)(c.south)(d.south)(e.south)};

as an approximation.

Note one thing: When you do node [right, below], the below setting overwrites right, so right doesn't have an effect. I.e. they're not cumulative. What actually happens is that right sets anchor=west, and below sets anchor=north, and a node can only have one anchor. The anchor determines which point of the node is placed at the given coordinate. The same thing happens for above, left.

If you do want the $x$ node below and right of the end point of the axis, use node [below right] {$x$}. The below right key sets anchor=north west, meaning that the top left corner of the node is placed at the end of the path.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[line width = .6pt,font=\footnotesize]
\draw[->] (-1,0) -- (6,0) node[below]{$x$};
\draw[->] (0,-1) -- (0,4) node[left]{$y$};
\node at (-.2,-.2) {$O$};

\draw (.5,.25) node (a) [above]{$A$} -- (.5,-1);
\draw (1.5,-.5) node (b) [above]{$B$} -- (1.5,-1);
\draw (2.5,.5) node (c) [above]{$C$} -- (2.5,-1);
\draw (3.5,2.5) node (d) [above]{$D$} -- (3.5,-1);
\draw (4.5,1.5) node (e) [above]{$E$} -- (4.5,-1);

\draw [shorten <=-5mm, shorten >=-5mm] plot [smooth] coordinates {(a.south)(b.south)(c.south)(d.south)(e.south)};
\end{tikzpicture}


\end{document}

enter image description here

For fun, a slight variation using a loop to draw the vertical lines and add nodes:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usepackage{alphalph} % for \alphalph and \AlphAlph, converting number to letter

\begin{document}
\begin{tikzpicture}[line width = .6pt,font=\footnotesize]
\draw[->] (-1,0) -- (6,0) node[right]{$x$};
\draw[->] (0,-1) -- (0,4) node[above]{$y$};
\node [below left] {$O$};

\foreach [count=\j] \y in {.25, -.5, .5, 2.5, 1.5}
  \draw (-.5+\j,-1) -- (-.5+\j,\y)
        coordinate [label=above:$\AlphAlph{\j}$] (\alphalph{\j});

\draw [shorten <=-5mm, shorten >=-5mm] plot [smooth] coordinates {(a)(b)(c)(d)(e)};
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.