# minipage layout not correct

I want to generate a document with graph at left and tikz code at the right. I try to use two minipage but it seems it always layout it as up and down. The minipage is 0.45\textwidth, why latex still can not put it side by side?

The example code as below:

\documentclass[12pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{listings}
\usepackage{color}
\usepackage{tikz}

\lstset{
backgroundcolor=\color{white},
breaklines=true,
language=TeX,
frame=single}

\begin{document}

\begin{minipage}{0.45\textwidth}
\begin{tikzpicture}
\draw (0,0) circle (5cm);
\end{tikzpicture}
\end{minipage}

\begin{minipage}{0.45\textwidth}
\begin{lstlisting}
\begin{tikzpicture}
\draw (0,0) circle (5cm);
\end{tikzpicture}
\end{lstlisting}
\end{minipage}

\end{document}


Current output by pdflatex as bleow:

You should consider using the showexpl package and use the LTXexample environment.

If you wish to have the code in an external file use the \LTXinputExample environment instead as the second example does in the MWE.

## Code:

\documentclass[12pt]{article}

%\usepackage{filecontents}% <-- Commented to prevent overwrite of test.tex
\begin{filecontents*}{test.tex}
\begin{tikzpicture}
\draw [ultra thick, blue] (0,0) circle (2.5cm);
\end{tikzpicture}
\end{filecontents*}

\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}
\usepackage{showexpl}

\lstset{
backgroundcolor=\color{white},
breaklines=true,
language=TeX,
frame=single,
}

\begin{document}
\begin{LTXexample}[
width=0.6\linewidth,
backgroundcolor=\color{yellow!40},
basicstyle=\small\ttfamily,
numbers=none
]
\begin{tikzpicture}
\draw [ultra thick, blue] (0,0) circle (2.5cm);
\end{tikzpicture}
\end{LTXexample}

\LTXinputExample[
width=0.6\linewidth,
backgroundcolor=\color{green!40},
basicstyle=\small\ttfamily,
numbers=none,
]{test}
\end{document}

• Good suggestion, but if I use \input{test.tikz} replace the tikzpicture, I will get "\input{test.tikz}" at the right, I wish the code at the right but not the command. any idea? Dec 30 '14 at 23:51
• @Beatlej: Have updated the example to show how to do that. Dec 31 '14 at 0:46
• Thanks, it's really good now. BTW, just now I see pgfplot gallery at pgfplots.sourceforge.net/gallery.html. it really looks nice. do you know which package can get the same behavior? Jan 4 '15 at 2:33
• @Beatlej: I am not sure I fully understand your question, but below each image is .tex file link that gives the entire .tex file and all the required packages. If that wasn't what you were asking I'd recommend you post a new question. Jan 5 '15 at 5:42