3
\begin{boxedlaw}{6.4in}
\colorbox[HTML]{F8E0E0}{
\begin{minipage}[c]{380px}
\begin{center}
\begine{verbatim}

\# define       LM_ENCA     18          //Port0
\# define       LM_ENCB     17          //Port0
\# define       RM_ENCA     29          //Port0
\# define       RM_ENCB     28          //Port0
\# define       LMDir       10          //Port0
\# define       RMDir       11          //Port0

\# define       LeftTx      21          //Port1
\# define       RightTx     20          //Port1
\# define       LfrontTx    17          //Port1
\# define       RfrontTx    16          //Port1

\# define      LeftRx       13          //Port0
\# define      RightRx      12          //Port0
\# define      LfrontRx     21          //Port0
\# define      RfrontRx     22          //Port0

\# define       Buzzer      31          //Port1
\# define       ModeSel     2           //Port0

\# define       GyroOut     5           //Port0
\# define       GyroOut4X   4           //Port0

\end{verbatim}
\end{center}
\end{minipage}}
\end{boxedlaw}

When I use this code I keep getting an error:

"! Missing $ inserted."
"! Missing } inserted."

I have declared this new environment at the start:

\usepackage{xcolor}         % Extended colors
\usepackage{color}         % Color extended names

%DEFINE ENVIRONMENT BLOCK
% Riddle
\newenvironment{colbox}[3]{        % Riddle environment
  \begin{center}                   % Centering minipage
    \colorbox[HTML]{#1} {          % Set's the color of minipage
      \begin{minipage}[b]{380px}   % Starts minipage
   \textbf{#2}\\ \textit{#3}       % Set's title and starts italic for text
  \end{minipage}}                  % End minipage
}{\end{center}}                    % End Riddle environment

The above environment is something I have copied from a different post on this forum. However being a novice with Latex I dont know if I can use it as it is. Any help would be great.

4
  • Welcome to TeX.sx! It would be create if you could add your code as a full minimal working example (MWE) which can be directly compiled by other people. Apr 18, 2012 at 18:42
  • I am confused; you defined a colbox environment (last snippet) but you use a boxedlaw environment in the first snippet; where is this environment defined? Also, there's a missing \begin{verbatim} in the first snippet. Apr 18, 2012 at 18:42
  • Sorry @GonzaloMedina. I forgot the \begin{verbatim}. What I am interested in is to get the text between the verbatim environment in a colred box with an outline around it. Apr 18, 2012 at 18:46
  • @KaranThakkar: You can't use verbatim inside a macro argument, here the \colorbox. Also, when you use verbatim you should turn the \# into #, right? Apr 18, 2012 at 18:50

1 Answer 1

4

You can't use the standard verbatim environment or the \verb command in the argument of another command. To write your verbatim material using a colored background, I would suggest you to use the listings package (refer to the package documentation to see all the features it provides):

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}

\definecolor{mycolor}{HTML}{F8E0E0}

\begin{document}

\begin{lstlisting}[backgroundcolor=\color{mycolor},xrightmargin=2cm]
# define       LM_ENCA     18          //Port0
# define       LM_ENCB     17          //Port0
# define       RM_ENCA     29          //Port0
# define       RM_ENCB     28          //Port0
# define       LMDir       10          //Port0
# define       RMDir       11          //Port0

# define       LeftTx      21          //Port1
# define       RightTx     20          //Port1
# define       LfrontTx    17          //Port1
# define       RfrontTx    16          //Port1

# define       LeftRx      13          //Port0
# define       RightRx     12          //Port0
# define       LfrontRx    21          //Port0
# define       RfrontRx    22          //Port0

# define       Buzzer      31          //Port1
# define       ModeSel     2           //Port0

# define       GyroOut     5           //Port0
# define       GyroOut4X   4           //Port0
\end{lstlisting}

\end{document}

enter image description here

For non-verbatim material, you have the mdframed and adjustbox packages.

3
  • Yes, and for non-verbatim material there are the mdframed and adjustbox packages. Apr 18, 2012 at 19:00
  • @MartinScharrer: yes; I added a little note to my answer. Apr 18, 2012 at 19:02
  • Okay. I guess I got the hint. Apr 18, 2012 at 19:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .