3
\documentclass{article}
\usepackage{tcolorbox}

\begin{document}

\begin{tcolorbox}[sidebyside=true, title=test]
\begin{verbatim}
this is <strong>not</strong> a test this is not a test this is not a test

$x+2=0$
$x=-2$
$x$ is negative
\end{verbatim}
\tcblower
Right part.
\end{tcolorbox}

\end{document}

enter image description here

The error is "Overfull \hbox too wide". I'm reading tcolorbox documentation but I don't understand why this happens.

The text in the left part should remain inside it, how to do it?

EDIT

Maybe the solution is to use lstlisting with breaklines=true instead of verbatim.

  • 1
    Happens that the verbatim text is to show the code just "as is". That include do not break lines. Seems that you really want a normal text with a monospaced teletype like \texttt{this}, that is very different of a verbatim text. – Fran Oct 13 '19 at 5:12
  • Oh it was just an example, but I need to write math and html inside it. I added a new snippet code. – sound wave Oct 13 '19 at 5:19
  • Maybe are you trying to do this? – Fran Oct 13 '19 at 5:22
  • Yes partially, I'd like to show raw code on the left, and latex output of a part of the code on the right. – sound wave Oct 13 '19 at 5:45
6

mwe

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}

\begin{tcblisting}{sidebyside,title=Test}

% Example of LaTeX code

This is \textbf{not} a test. This is not a test. This is not a test. This is not a test.  

$x+2=0$

$x=-2$ \dotfill $x$ is negative

\end{tcblisting}
\end{document}

In case that the right side should be different in some way to the output of the listed code compiled with LaTeX:

mwe2

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}

\begin{tcblisting}{sidebyside,title=Test, listing and comment, 
comment={

% Example of LaTeX code

This is \textbf{not} a test. (...)

$x+2=0$

$x=-2$ \dotfill $x$ is negative

\bigskip 

\ttfamily\color{magenta} This is (more or less) the result
}}

% Example of HTML + LaTeX code

This is <strong>not</strong> a test. This is not a test. This is not a test. This is not a test.  

$x+2=0$

$x=-2$ \dotfill $x$ is negative

\end{tcblisting}
\end{document}
| improve this answer | |
  • Thank you! Is there a way to show in the right part the output of a piece of code written in the left part without having to repeat that piece of code twice? – sound wave Oct 15 '19 at 1:10
  • Moreover, is there a way to automatically set the width of the right part to match the width of its content? – sound wave Oct 15 '19 at 1:16
  • 1
    @soundwave (1) The first example does exactly that, doesn't it? (2) Sure, add to the environment lefthand ratio=0.65 – Fran Oct 15 '19 at 2:18
  • (1) With "piece of code" I mean a small part of the full code, for example on the left part I would like to gets dislayed the full code, while on the right part I would like to get displayed only "$x+2=0$" without having to repeat the code "$x+2=0$" two times. (2) I mean that I don't have to manually write the ratio, but that it is computed automatically using the width of the right part. – sound wave Oct 15 '19 at 2:45
  • 1
    tcolorbox macros cannot guess which part you of the verbatim code you want to show compiled and which part not. Let it see, that al least mean that you will define previously in some way that parts, and if they must be compiled or not (said chunks type 1 and 2), and then devise how to pass both types verbatim in one side and only the chunks type 2 on the other. Even if there was some environment ready to do this, it seems to much work to avoid a simple cut and paste. – Fran Oct 15 '19 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.