Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have grid-formatted data:

1 2 3
4 5 6 
7 7 9

I'd like to display this as above in a LaTeX document compiled with pdfLaTeX.

I've thought about using the TikZ Matrix library and the AMSMath Matrix library, but, in the resulting document, highlighting the data (as printed by AMSMath) and copy-pasting it into a notepad shows the following:

1
4
7
2
5
7
1
3
6
9

I'd like a nice grid-formatted result when I hit paste - how can I compile my PDF to produce such a result?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

You suggested the answer yourself: A TikZ matrix will do just that (which is pretty awesome!):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes]{
1 & 2 & 3\\
4 & 5 & 6\\
7 & 8 & 9\\% <- Without this %, there would be a trailing "1" in the copied text
};
\end{tikzpicture}
\end{document}

gives

and copying and pasting from the PDF gives

1 2 3
4 5 6
7 8 9

Or, to draw the grid itself, along with the data (as described at TikZ matrix as a replacement for tabular, for example):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix [matrix of nodes, style={nodes={rectangle,draw,minimum width=3em}}, minimum height=1.5em, row sep=-\pgflinewidth, column sep=-\pgflinewidth]
{
1 & 2 & 3\\
4 & 5 & 6\\
7 & 8 & 9\\% <- Without this %, there would be a trailing "1" in the copied text
};
\end{tikzpicture}
\end{document}
share|improve this answer
    
Jake, I had another piece of code in which I had put boxes around each number (to make a grid) - in that code the copy didn't come out right. Would you know how to do this off-handedly? –  Richard Apr 5 '12 at 20:53
1  
Nevermind, I figured it out - odd it didn't work the first time! –  Richard Apr 5 '12 at 20:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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