I am using pgfplotsable and I can't seem to figure out an easy way to both a) set a specific with for my columns and b) center the text within the columns. No matter what I try, one seems to override the other.
Here is an example of what I have been trying
\documentclass[12pt]{book}
\usepackage{array, booktabs}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\renewcommand{\arraystretch}{1.5}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usepackage{makecell}
% Using this in conjunction with the pgfplotstable
\begin{document}
\begin{table}[htpb]
\centering
\pgfplotstabletypeset[
col sep=&,
row sep=\\,
string type,
columns = {Divisor, Rule, Example},
columns/Divisor/.style={column name={ \bf Divisor},column type={p{.1\textwidth} } } ,
columns/Rule/.style={column name={ \bf Rule},column type={p{.4\textwidth} } } ,
columns/Example/.style={column name={ \bf Example},column type={p{.3\textwidth} } } ,
every head row/.style=
{before row=\toprule\toprule, after row=\bottomrule},
every last row/.style=
{after row=\bottomrule\bottomrule},
]
{
Divisor & Rule & Example \\
2 & If the last digit is 0, 2, 4, 6 or 8 & $C'mon\ Man!$ \\ \hline
3 & If sum of digits is divisible by 3 & $ 921 \rightarrow \frac{9 + 2 + 1}{3} = 4 $ \\ \hline
4 & If number formed by last two digits is divisible by 4 & $ 524 \rightarrow\ \frac{24}{4} = 6 $ \\ \hline
5 & If last digit is 0 or 5 & $C'mon\ Man!$ \\ \hline
6 & If it is divisible by 2 AND divisible by 3 & $\frac{468}{2} = 234,\ \frac{468}{3} = 156$ \\ \hline
6 & If it is divisible by 2 AND divisible by 3 & \Gape[6pt]{\makecell{$\frac{468}{2} = 234$ \\ {} \\ $\frac{468}{3} = 156$}} \\ \hline
7 & No rule exists & {} \\ \hline
8 & If number formed by last three digits is divisible by 8 & $ 24,296 \rightarrow \frac{296}{8} = 37 $ \\ \hline
9 & If sum of digits is divisible by 9 & $549 \rightarrow \frac{5+4+9}{9} = 2$ \\
}
\caption{Divisibility rules for the integers less than 10.}
\end{table}
\end{document}
The output looks like this (ignore the repeated entry for the rules for divisibility by 6 — I was just playing around with the \makecell and \Gape commands!).
All I want to be able to do is center the text within each column using a global command, rather than adding \centering to each cell.
I have also tried
\begin{table}[htpb]
\centering
\resizebox{\textwidth}{!}{
\pgfplotstabletypeset[
and removed the "column type={p{.3\textwidth} }" commands. While that accomplishes the task of centering everything, it shriks the entire table down and text becomes too small.
Any help would be appreciated.
Best Answer
like this?
edit:
C
(you can choose another letter for its name). it is derived fromp{...}
with added option\centering
. since it interfere with\\
on the end of rows, is added\arraybackslash
which restore original meaning of\\
.\dimexpr
defined inlatex
kernel. to have table width equal to\textwidth
you should:\tabcolsep
. table span six this lengths (each column has two, one on begin column, one on its end), but two of them (the first and the last one) are eaten by@{}
on beginning and end of column specification. therefore the width, which is shared between columns is\textwidth - 4\tabcolsep
addendum:
so far i didn't bother with table content. now i inspect it ... so below are some suggestion how to improve it:
p{...}
column type usem{..}
type (provided by packagearray
).m{...}
type is not compatible withmakecell
package, it should be removed\hline
use\midrule
amsmath
package foraligned
environmentwith this changes your table become: