Graphics, Figures & TablestikZ | Stretch Picture horizontally

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

tikZ | Stretch Picture horizontally

Post by ghostanime2001 »

With my 2 figures below:
How can I have the second figure the exact width as the 1st figure above? I have tried to stretch horizontally using \begin{tikzpicture}[x=6cm] but that widens it wayyyyyyy too much :cry: What can I do? thanks..

Code: Select all

\documentclass{article} 
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,1.1) -- (6,1.1) node[midway,above] {B}; %top
\draw (0,-1.1) -- (6,-1.1); %bottom
\draw (0,-1) cos (6,0); %top curve
\draw (0,1) cos (6,0); %bottom curve
\draw (6,1.1) -- (6,-1.1) node[midway,anchor=west] {\quad $n=1$ \quad $L=\dfrac{1}{4}\lambda_{1}$}; %right
\draw[fill=black] (6,0) circle (1.6pt); %circle
\end{tikzpicture} \par\medskip
\begin{tikzpicture}
\draw (0,1.1) -- (3,1.1) node[midway,above] {C}; %top
\draw (0,-1.1) -- (3,-1.1); %bottom
\draw (0,1) cos (1,0) sin (2,-1) cos (3,0); %top curve
\draw (0,-1) cos (1,0) sin (2,1) cos (3,0); %bottom curve
\draw (3,1.1) -- (3,-1.1) node[midway,anchor=west] {\quad $n=3$ \quad $L=\dfrac{3}{4}\lambda_{3}$}; %right
\draw[fill=black] (3,0) circle (1.6pt); %circle
\draw[fill=black] (3,0) circle (1.6pt); %circle
\end{tikzpicture}
\end{document}

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Stretch Picture horizontally

Post by localghost »

Your approach with a new x unit goes in the right direction. But since the lower picture is only half as wide as the upper one, you only have to double the horizontal units. So, instead of 6cm choose 2cm and you've got what you want.

P.S.: Very good minimal example.


Thorsten
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: tikZ | Stretch Picture horizontally

Post by ghostanime2001 »

How can I make my diagram a postscript file so that I can use it like a image in a \includegraphics command and align it to the top of a question number?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Stretch Picture horizontally

Post by localghost »

Not necessary.

Code: Select all

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}

\begin{document}
  \begin{enumerate}
    \item \leavevmode\vadjust{\vspace{-\baselineskip}}\newline
      \begin{tikzpicture}
        \draw (0,1.1) -- (6,1.1) node[midway,above] {B}; %top
        \draw (0,-1.1) -- (6,-1.1); %bottom
        \draw (0,-1) cos (6,0); %top curve
        \draw (0,1) cos (6,0); %bottom curve
        \draw (6,1.1) -- (6,-1.1) node[midway,anchor=west] {\quad $n=1$ \quad $L=\dfrac{1}{4}\lambda_{1}$}; %right
        \draw[fill=black] (6,0) circle (1.6pt); %circle
      \end{tikzpicture}

      \begin{tikzpicture}[x=2cm]
        \draw (0,1.1) -- (3,1.1) node[midway,above] {C}; %top
        \draw (0,-1.1) -- (3,-1.1); %bottom
        \draw (0,1) cos (1,0) sin (2,-1) cos (3,0); %top curve
        \draw (0,-1) cos (1,0) sin (2,1) cos (3,0); %bottom curve
        \draw (3,1.1) -- (3,-1.1) node[midway,anchor=west] {\quad $n=3$ \quad $L=\dfrac{3}{4}\lambda_{3}$}; %right
        \draw[fill=black] (3,0) circle (1.6pt); %circle
        \draw[fill=black] (3,0) circle (1.6pt); %circle
      \end{tikzpicture}
    \item
  \end{enumerate}
\end{document}
Post Reply