# File icon (folded corner rectangle) frame around text

I would like to present code listings with a "file icon box". Something like this:

I'm aware of listings package allowing rectangle frames. My interest is in the specific shape of the frame. I think it is not specific to source code. If it does not exist off-the-shelf, I'm not afraid of some coding to achieve this.

-
I would define my own listings environment (\lstnewenvironment) which draws the box using TikZ around the listing. – Martin Scharrer Aug 5 '11 at 10:33

I would define my own listings environment (\lstnewenvironment) which draws the box using TikZ around the listing:

\documentclass{article}

\usepackage{listings}
\usepackage{tikz}

\newlength{\cornerlength}
\setlength{\cornerlength}{1cm}

\tikzset{listingborder/.style={thick}}

\makeatletter
\lstnewenvironment{mylisting}[1][]{%
\lstset{#1}%
\setbox0\hbox\bgroup\color@setgroup
}{%
\color@endgroup\egroup
\begin{tikzpicture}
\node (L) [text width=\linewidth] {%
\usebox{0}%
};
\draw [listingborder]
(L.north west)
-- ([xshift=-\cornerlength]L.north east)
-- ([yshift=-\cornerlength]L.north east)
-- (L.south east)
-- (L.south west)
-- cycle;
\draw [listingborder]
([yshift=-\cornerlength]L.north east)
-| ([xshift=-\cornerlength]L.north east);
\end{tikzpicture}%
}
\makeatother

\begin{document}

\begin{mylisting}[language=tex,basicstyle=\ttfamily]
\lstnewenvironment{mylisting}[1][]{%
\lstset{#1}%
\setbox0\hbox\bgroup\color@setgroup
}{%
\color@endgroup\egroup
\begin{tikzpicture}
\node (L) [text width=\linewidth] {%
\usebox{0}%
};
\draw [listingborder]
(L.north west)
-- ([xshift=-\cornerlength]L.north east)
-- ([yshift=-\cornerlength]L.north east)
-- (L.south east)
-- (L.south west)
-- cycle;
\draw [listingborder]
([yshift=-\cornerlength]L.north east)
-| ([xshift=-\cornerlength]L.north east);
\end{tikzpicture}%
}
\end{mylisting}

\end{document}


You still need to add the waved line at the bottom. Also note that usually you can wrap the node around the environment content be replacing \node {..}; with \node \bgroup and \egroup;, however, this didn't worked for the listings environment. Most likely some of the verbatim trickery causes issues. (This is funny because verbatim should work inside a TikZ node)

-
Will this break across pages nicely? – Seamus Aug 5 '11 at 10:59
@Seamus: No, that wasn't requested. If this is required I would use the code in my answer to your question Test if a paragraph has a page break in it?. The different layout can easily be added. – Martin Scharrer Aug 5 '11 at 11:04
yes that was a somewhat cheecky question. But since the normal listings frame environment does break across pages, I wonder if you could "piggy back" on that by just, say, adding a triangle to the top right corner of that, rather than drawing the box yourself... – Seamus Aug 5 '11 at 11:11
thank you very much, it's my first time on tex.stackexchange and I'm delighted and impressed of the answer (as of response time!) – FabienAndre Aug 5 '11 at 12:23