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 want to float a smaller table to the right of my text. Here is an example of the code:

% Example Table
\documentclass{minimal}
\begin{filecontents*}{scientists.csv}
name,surname,age
Albert,Einstein,133
Marie,Curie,145
Thomas,Edison,165
\end{filecontents*}

% Read in Table


 \documentclass{article}
 \usepackage{pgfplotstable}
 \begin{document}
\section*{Section 1}  I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. 



\begin{table}
\pgfplotstabletypeset[
    col sep=comma,
    string type,
    columns/name/.style={column name=Name, column type={|l}},
    columns/surname/.style={column name=Surname, column type={|l}},
    columns/age/.style={column name=Age, column type={|c|}},
    every head row/.style={before row=\hline,after row=\hline},
    every last row/.style={after row=\hline},
    ]{scientists.csv}
\end{table}
\end{document}

Thanks for help with a simple question,

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can use the wraptable environment from the wrapfig package; a little example:

\documentclass{article}
\begin{filecontents*}{scientists.csv}
name,surname,age
Albert,Einstein,133
Marie,Curie,145
Thomas,Edison,165
\end{filecontents*}

% Read in Table

\usepackage{pgfplotstable}
\usepackage{wrapfig}

\begin{document}
\section*{Section 1}  
\begin{wraptable}{r}{5cm}
\centering
\pgfplotstabletypeset[
    col sep=comma,
    string type,
    columns/name/.style={column name=Name, column type={|l}},
    columns/surname/.style={column name=Surname, column type={|l}},
    columns/age/.style={column name=Age, column type={|c|}},
    every head row/.style={before row=\hline,after row=\hline},
    every last row/.style={after row=\hline},
    ]{scientists.csv}
\end{wraptable}
I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. 

\end{document}

enter image description here

Of course (as a suggestion), the booktabs package can contribute to increase the quality of your table:

\documentclass{article}
\begin{filecontents*}{scientists.csv}
name,surname,age
Albert,Einstein,133
Marie,Curie,145
Thomas,Edison,165
\end{filecontents*}

% Read in Table

\usepackage{pgfplotstable}
\usepackage{wrapfig}
\usepackage{booktabs}

\begin{document}
\section*{Section 1}  
\begin{wraptable}{r}{5cm}
\centering
\pgfplotstabletypeset[
    col sep=comma,
    string type,
    columns/name/.style={column name=Name, column type={@{}l}},
    columns/surname/.style={column name=Surname, column type={l}},
    columns/age/.style={column name=Age, column type={c@{}}},
    every head row/.style={before row=\toprule,after row=\cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(l){3-3}},
    every last row/.style={after row=\bottomrule},
    ]{scientists.csv}
\end{wraptable}
I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. I want to have this text wrap around the small table to the right.  This is actually a longer paragraph which would fill the side of the page. 

\end{document}

enter image description here

share|improve this answer
    
Thanks -- when I do that, the table appears over my text... How can I prevent this? Nevermind, this occurred because it was over an itemize –  mike Dec 10 '12 at 18:18
    
@mike yes; wraptable and wrapfigure don't behave well near lists; you can use the environments after a list and after using \par (or leaving a blank line) in-between. On a side note, I added another option to my answer using the booktabs package. –  Gonzalo Medina Dec 10 '12 at 18:26

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.