1

This question already has an answer here:

I want to highlight a certain element in this matrix from matlab output. How can I do this in the verbatim environment?

\begin{verbatim}

P =

1.0000    0.7000         0         0         0
     0         0    0.5000         0         0
     0    0.3000         0    0.6500         0
     0         0    0.5000         0         0
     0         0         0    0.3500    1.0000
\end{verbatim}

marked as duplicate by Werner, barbara beeton, Svend Tveskæg, user13907, user2478 Sep 20 '15 at 20:38

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.

7

The standard verbatim environment is too basic. You could use instead the listings package and its escapeinside feature to escape to LaTeX for the highlighting:

\documentclass[11pt]{article}
\usepackage{listings}
\usepackage{xcolor}

\lstset{
  basicstyle=\ttfamily,
  escapeinside=||
}

\begin{document}

\begin{lstlisting}
P =

 |\textcolor{cyan}{1.0000}|    0.7000         0         0         0
     0         0    0.5000         0         0
     0    0.3000         0    |\colorbox{magenta!30}{0.6500}|         0
     0         0    0.5000         0         0
     0         0         0    0.3500     |\textcolor{orange}{1.0000}|
\end{lstlisting}

\end{document}

enter image description here

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