2

I want to crop the page to exactly fit the tikz graph in it. When i used standalone document class, all the page content became on one line. Here is my code

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzstyle{myarrow}=[draw=black,-triangle 45]
\begin{document}
$X^2$ = $\frac{c}{b}$ \\

\begin{tikzpicture}
    \draw [myarrow] (0,0) -- (13,0) node [at end, below] {$\lambda$};
    \draw (0,2.2) -- (12,2.2);
    \draw[ultra thick, black] (0,0) sin (3,2);
    \draw[ultra thick, red] (3,2) cos (6,0);
    \draw[ultra thick, black] (6,0) sin (9,-2);
    \draw[ultra thick, red] (9,-2) cos (12,0);
\end{tikzpicture}\\

$A$  \hspace{1cm}Hello \\

C               \hspace{1.3cm}hello  \\

B        \hspace{1cm}hello \\

d               \hspace{1.4cm}hello  \\
\end{document}

I want the result to be like this enter image description here

But here is what i got enter image description here

I also tried preview but it didn't work Got the ideas from here

Fadwa
  • 571

1 Answers1

2

You can use the varwidth option for standalone to enclose the contents in a varwidth environment (from the varwidth package). I had to specify some width for the option to avoid the \lambda and the arrow on the left from being cropped out:

\documentclass[varwidth=80cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzstyle{myarrow}=[draw=black,-triangle 45]

\begin{document}

$X^2$ = $\frac{c}{b}$ \par
\begin{tikzpicture}
    \draw [myarrow] (0,0) -- (13,0) node [at end, below] {$\lambda$};
    \draw (0,2.2) -- (12,2.2);
    \draw[ultra thick, black] (0,0) sin (3,2);
    \draw[ultra thick, red] (3,2) cos (6,0);
    \draw[ultra thick, black] (6,0) sin (9,-2);
    \draw[ultra thick, red] (9,-2) cos (12,0);
\end{tikzpicture}

$A$  \hspace{1cm}Hello\par\bigskip

C               \hspace{1.3cm}hello\par\bigskip

B        \hspace{1cm}hello\par\bigskip

d               \hspace{1.4cm}hello

\end{document}

enter image description here

You can use the border option to add some border, if required.

Not related to the question, but please never use \\ followed by \par (or a blank line); you can use \par\bigskip instead, if need be. I don't quite understand why you have all those \hspaces in your code. Perhaps you are trying to achieve an enumerated list? In this case, use the enumerate environment.

Gonzalo Medina
  • 505,128