monospaced fonts not respecting spaces?
\texttt
just sets the typeface. It doesn't change how TeX sees spaces. If you want that, then you need to use some kind of verbatim macro or environment. Or fiddle with the catcode of space (NOT RECOMMENDED!)
You can use the package listings
or the environment verbatim
. An example you will see in the following MWE. Could it be that a table would better fit your issue?
%http://tex.stackexchange.com/questions/70007/monospaced-fonts-not-respecting-spaces
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\begin{document}
\par\texttt{this is monospaced text Where is the spaces ? !!!}
\begin{verbatim}
this is monospaced text Where is the spaces ? !!!
\end{verbatim}
\begin{lstlisting}[basicstyle=\ttfamily]
this is monospaced text Where is the spaces ? !!!
\end{lstlisting}
\begin{lstlisting}[basicstyle=\ttfamily,showspaces=true]
this is monospaced text Where is the spaces ? !!!
\end{lstlisting}
\end{document}
Another approach for short verbatim text is to use the \Verb
command from the fancyvrb
package; I added the obeytabs
option and used tabsize
to recover the alignment inside the \matrix
(the characters are spaced using tabs):
Apparently, when I copy the code from my editor to this site the tabs get lost. You need to use A(tab)B(tab)C(tab)D
and Ac(tab)Ad(tab)Be(tab)Cf
in the code below, where (tab)
stands for a tab in your editor:
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{tikz}
\usetikzlibrary{matrix}
\fvset{obeytabs}
\begin{document}
\begin{tikzpicture}%
\matrix (m) [matrix of nodes, every node/.style={font=\ttfamily},%
row 1/.style={text width=7em, align=left},
row 2/.style={text width=7em, align=left}]
{
\Verb[tabsize=2]+A B C D+\\
\Verb[tabsize=1]+Ac Ad Be Cf+\\
};
\end{tikzpicture}
\end{document}
Using the \lstinline
command from the listings
package, there's no need to use tabs; simple spaces will behave as expected:
\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}%
\matrix (m) [matrix of nodes, every node/.style={font=\ttfamily},%
row 1/.style={text width=7em, align=left},
row 2/.style={text width=7em, align=left}]
{
\lstinline+A B C D+\\
\lstinline+Ac Ad Be Cf+\\
};
\end{tikzpicture}
\end{document}