I think the good package is showexpl
.This package works with listings
.
I work actually on the tkzexample package. The last version is on ctan but I try to finish the doc. You can present the source code and the result but it's not possible to highlight the syntax.
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz,tkzexample}
\usetikzlibrary{shapes,arrows}
\colorlet{graphicbackground}{red!10!white}%
\colorlet{codebackground}{blue!10!white}%
\colorlet{codeonlybackground}{gray!20}
\begin{document}
\parindent=0pt
\begin{tkzexample}[small,width=8cm,overhang,frame tex=red,frame code=blue]
\begin{minipage}{6cm}
\section{Minipage et èçéà\&§}
Ceci est un test pour "minipage"
\end{minipage}
\end{tkzexample}
\hspace{24pt}
\begin{tkzexample}[small,width=3cm,frame tex=red,frame code=blue]
\begin{tikzpicture}
\draw (0,0) node[circle,
shade,
ball color=Peach,minimum size=2cm]{};
\end{tikzpicture}
\end{tkzexample}
\hspace{24pt}
\begin{tkzltxexample}[line frame width=2pt]
\begin{tkzexample}[width=4cm,frame tex=red,frame code=blue]
\tikz[baseline]
\node [circle,line width=1ex,draw=blue,fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{tkzltxexample}
\hspace{24pt}
\begin{tkzexample}[width=4cm,frame tex=red,frame code=blue]
\tikz[baseline]
\node [circle,line width=1ex,draw=blue,fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\hspace{24pt}
\begin{tkzexample}[width=3cm,frame tex=red,frame code=blue]
$x \mathbin{\tikz[baseline] \draw[|->,>=triangle 45]%
(0pt,.5ex) -- (8ex,.5ex);} f(x)$
\end{tkzexample}
\end{document}
This might be what you're after:
...
\newcommand{\insertbox}[1]{%
\llap{\smash{\parbox[t]{2.5cm}{#1}}}%
}
...
\address{\insertbox{hello world \\ some text \\ more text}%
21 Bridge Street \\ Smallville \\ Dunwich DU3 4WE}
\llap
allows for a zero-width box left overlap, while \smash
ensures that you can have a line-break that does not influence the line breaking in the remainder of the \address
command. Otherwise Smallville
would be pushed down with each \\
in \insertbox
. Finally, a \parbox[t]{2.5cm}
provides a 2.5cm wide (paragraph/left-aligned) box, aligned at the top [t]
.
Best Answer
Something like this?
If the order of arguments is important you can use
xparse
:using
\NewDocumentCommand
rather than\newcommand
.