# Including HTML code side by side in Latex [duplicate]

This question already has an answer here:

I want to write HTML codes of two pages side by side in LaTeX like as follows:

<html>   <html>
<head>   <head>
</head>  </head>
<body>   <body>
...      ...
</body>  </body>
</html>  </html>


I know how to include HTML code in LaTeX but I have no clue how will I achieve it. So if anyone please help me regarding this I will be grateful. Thank you.

EDIT: I have tried it with the help of table as shown below, but it is giving errors.

\begin{table}[htb]
\parbox{.45\linewidth}{
\centering
\begin{tabular}{c}

\begin{lstlisting}[language=html]
<html>
<head>
</head>
<body>
...
</body>
</html>
\end{lstlisting}
\end{tabular}
}
\hfill
\parbox{.45\linewidth}{
\centering
\begin{tabular}{c}

\begin{lstlisting}[language=html]
<html>
<head>
</head>
<body>
...
</body>
</html>
\end{lstlisting}
\end{tabular}
}
\end{table}

-

## marked as duplicate by Jubobs, Werner, Jesse, Svend Tveskæg, SperavirMar 6 at 2:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

So what you actually want is to put two blocks of HTML code side by side, so it can be compared and stuff? could you post what you have so far? –  Count Zero Jun 10 '13 at 9:58
Yes Sir you are right. I exactly I want that. –  Joy Jun 10 '13 at 10:03

## 2 Answers

How about using minipage environments for the two columns?

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{listings}
\lstset{
breaklines=true,
breakatwhitespace=true,
}
\begin{document}

\begin{minipage}[t]{0.45\textwidth}
\begin{lstlisting}[language=html]
<html>
<head>
</head>
<body>
...
</body>
</html>
\end{lstlisting}
\end{minipage}
\hfill
\begin{minipage}[t]{0.45\textwidth}
\begin{lstlisting}[language=html]
<html>
<head>
</head>
<body>
...
</body>
</html>
\end{lstlisting}
\end{minipage}

\end{document}

-
Thanks a lot, Sir :) It's working. But I could not include the package geometry with showframe option. Without that it is working. –  Joy Jun 10 '13 at 10:15
Sir one problem is occurring, that sometimes lines from left html code get intermixed with that of right. How will I prevent that? –  Joy Jun 10 '13 at 10:20
@Joy: use line breaks in your code. –  Willie Wong Jun 10 '13 at 12:28
@Joy Call me Jubobs, not "Sir" :) If you want to allow line breaks in your code, you should set breaklines=true; see my last edit. –  Jubobs Jun 10 '13 at 13:25

Use package varwidth for a variable width of the parboxes:

\documentclass{article}
\usepackage{listings}
\usepackage{varwidth}
\begin{document}
\noindent
\begin{varwidth}{0.49\linewidth}
\begin{lstlisting}[language=html]
<html>
<head>
</head>
<body>
...
</body>
</html>
\end{lstlisting}
\end{varwidth}
\qquad%\hfill
\begin{varwidth}{0.49\linewidth}
\begin{lstlisting}[language=html]
<html>
<head>
</head>
<body>
...
</body>
</html>
\end{lstlisting}
\end{varwidth}

\end{document}


-
But sometimes lines from left html code get intermixed with that of right, if that line from left is bit long. How will I prevent that? –  Joy Jun 10 '13 at 10:22
then use \begin{varwidth}{\linewidth} instead, then they can be each as wide as the linewidth. If one is wider than that use a bigger value or use something like basicstyle=\footnotesize\ttfamily for the listings setting. –  Herbert Jun 10 '13 at 10:24
Sorry sir, I do not understand the last part of your answer i.e. basicstyle for listings setting. Could you please clarify? –  Joy Jun 10 '13 at 10:28
\begin{lstlisting}[language=html,basicstyle=\footnotesize\ttfamily] –  Herbert Jun 10 '13 at 10:37
Sorry Sir, even after using that lstlisting setting problem is not solved. –  Joy Jun 10 '13 at 10:43