BUG: pivot_table margins fails with ordered categorical variables
#### Code Sample

```python
import pandas as pd
import numpy as np
np.random.seed(42) # for reproducibility

# Generate fake data
n_elem = 10
test = pd.DataFrame(data={'col1':list('A'*n_elem) + list('B'*n_elem), 
                          'col2':np.random.choice(3, n_elem*2),
                          'col3':np.random.normal(size=n_elem*2)})

test['col1'] = test['col1'].astype('category') 
test['col2'] = test['col2'].astype('category').cat.as_ordered() 
```
#### Problem description
When using `pivot_table` with `margins=True` the `aggfunc` shuffles the order of the columns. For example:
```python
test.pivot_table(index=['col1'], columns=['col2'], values=['col3'], aggfunc=[np.shape], margins=True)
```
returns 
```python
      shape                   
      col3                   
col2     0     1     2    All
col1                         
A     (3,)  (1,)  (6,)  (10,)
B     (2,)  (5,)  (3,)  (10,)
All   (6,)  (9,)  (5,)  (20,)
```
and you can see that the sum across rows are wrong.

#### Expected Output
If we set the categorical variable as unordered
```python
test['col2'] = test['col2'].astype('category').cat.as_unordered() 
```
then the sum for each column is correct:
```python
     shape                   
      col3                   
col2     0     1     2    All
col1                         
A     (3,)  (1,)  (6,)  (10,)
B     (2,)  (5,)  (3,)  (10,)
All   (5,)  (6,)  (9,)  (20,)
```

#### Output of ``pd.show_versions()``
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.4
pytest: None
pip: 18.0
setuptools: 40.0.0
Cython: 0.28.5
numpy: 1.15.0
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: None
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
</details>
