4

Putting a tikzpicture normpdf_2d.tex

    \input{./Figures/chapter6/normpdf_2d.tex}

on its own is fine. but, putting it nto a \tabularx environment won't compile. Why? What property does this environment need to know about \input before it works? The size/width?

This however is fine:

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{figure}
\begin{tabular}{C{.48\textwidth}C{.48\textwidth}}
 \subfloat[Subfigure 1] {\input{./Figures/chapter6/normpdf_3d.tex}}
 \subfloat[Subfigure 1] {\input{./Figures/chapter6/normpdf_2d.tex}}
\end{tabular}
\end{figure}

This not:

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs,multirow}
\usepackage{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}
\usepackage{tabularx}
\usepackage{subfig}
\usepackage{filecontents}



       \usepgfplotslibrary{external}
        \tikzexternalize

     \begin{filecontents*}{normpdf_2d.tikz}
\documentclass[tikz,border=12pt]{standalone}
\usepackage{pgfplots}
\usepackage{subfig}
\usepackage{tabularx}
\pgfplotsset{compat=newest}
   %\usepgfplotslibrary{external}
%\tikzexternalize
\begin{document}
\definecolor{mycolor1}{rgb}{0,0.75,0.75}

\begin{tikzpicture}

\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmin=0, xmax=6,
xlabel={cfu (Y)},
ymin=0, ymax=1,
ylabel={Probability density},
legend style={draw=black,fill=white,legend cell align=left}
]
\addplot [
color=blue,
solid,
line width=1.5pt
]
table{
0.164920894751145 0.145245471693298
0.34898483521757 0.314105513485571
0.400206868657802 0.375704063846473
0.431202365194672 0.415565960090126
0.468283168514601 0.465368046385591
0.468819173063357 0.466102333522882
0.541086963948335 0.567617590141928
0.558035142464694 0.591815958738304
0.558424656178589 0.592372256340699
0.567763246195775 0.605704754250354
0.588442297122976 0.635140815037755
0.588968308388865 0.635887013738116
0.589496900268574 0.636636709024852
0.615575125108802 0.673361419528354
0.656478830152384 0.729356371745445
0.663734249176834 0.739001710618186
0.681134429788414 0.761691427683771
0.699206339854542 0.784509230520803
0.703174714510729 0.789406773282464
0.710293205919594 0.798082837552696
0.738324318268112 0.830765143080553
0.743729355370618 0.836772857231647
0.7628624687978 0.857202030543563
0.789650071275085 0.883431847212714
0.848769035460717 0.93014828764704
0.857054257851899 0.935346913150545
0.867490832222506 0.941393771927579
0.892221633180695 0.953428704494102
0.910732799951076 0.96026629015755
0.942439202692875 0.967534739622871
0.964173551423469 0.969220797343017
0.966490207360103 0.969241291138126
0.972340307586979 0.969156381555276
0.999815929196087 0.966143308438322
1.01840762385923 0.96167588822653
1.02422624912665 0.959879519150392
1.04820841787849 0.950503937405069
1.05040526585597 0.949488520832702
1.05188064663965 0.948792015052305
1.06421741151945 0.942513866116551
1.06952744475091 0.939564533487357
1.07377729763307 0.937098333090976
1.10837980144772 0.913625640841771
1.12655613304724 0.898983298828636
1.13577066384758 0.89098627132941
1.1580472276478 0.870142330490693
1.15859589504013 0.869603007065865
1.18051156035791 0.847100007296536
1.21401730562959 0.809369022407148
1.33027028384446 0.656408242977467
1.33483660875034 0.649970375448687
1.37629546726956 0.590995765951455
1.39873034424263 0.558976024508442
1.42011477374599 0.528607866819228
1.49811243643743 0.421418636969251
1.55782976646071 0.345795703108512
1.60683136399288 0.289407680329164
1.67872959183145 0.217237684951087
1.70586524394617 0.193407783948843
2.09859653835273 0.0221208957939459
2.23050096301146 0.0087062390469457
};
\addlegendentry{n=5};

\addplot [
color=green!50!black,
solid,
line width=1.5pt
]
table{
1.11061716777245 0.25439255248339
1.32152703852018 0.444545345197107
1.33743602693433 0.460242989969573
1.42547263125263 0.547313752669856
1.50599624519356 0.623697850962722
1.5261804928616 0.641779387498937
1.573838875732 0.682042674974274
1.57730219814673 0.684816482012706
1.62699159305991 0.721956657982538
1.63486458952984 0.727347067179288
1.68630344515834 0.758807092685913
1.71784982886711 0.774600265244482
1.83289913575602 0.806644546215021
1.86864417529802 0.807887335418516
1.88963804306077 0.806645110709114
1.90172633188334 0.805269969440086
1.97361138903204 0.787332803216098
2.16847522483986 0.665794197723055
2.26107642525521 0.582137894844234
2.44093902647085 0.40561167899897
2.55728899719626 0.299162501222641
2.72596462417501 0.174351769994033
3.14460320890567 0.0275718440302502
};
\addlegendentry{n=10};

\addplot [
color=red,
solid,
line width=1.5pt
]
table{
1.58873251442874 0.139270685555603
1.75094674410523 0.187648610352166
2.00056999517431 0.274533946251121
2.27705604989095 0.374550491086161
2.29596621491152 0.380969240114346
2.41176717604408 0.417753266892818
2.41614828744096 0.419044488634782
2.45981848928711 0.431445200552556
2.51461996380818 0.44569150663875
2.63732800530387 0.471433199097579
2.67540149916467 0.47748693150892
2.72686458640717 0.484091305194831
3.03140642922051 0.483465535521604
3.07384878732821 0.477986374915163
3.1895413994593 0.4569517259234
3.25640618890004 0.441099033384993
3.39991043346777 0.399612809225554
3.7029148147097 0.292622994026572
3.94491621538283 0.206344381423128
4.36469219413918 0.0911022396340956
4.68444030939428 0.0408178745872097
};
\addlegendentry{n=15};

\addplot [
color=mycolor1,
solid,
line width=1.5pt
]
table{
2.44469092422533 0.134047643683245
2.99469910210473 0.332559909167666
3.05373235366556 0.355888865309276
3.31377765482139 0.447946402923478
3.41066336498647 0.474278454032695
3.73828133650772 0.512840458011838
4.11146934521349 0.451592119764443
4.12204843744243 0.448459021945289
4.13062375797785 0.445874763291985
4.34434429091486 0.371194128891267
5.24212616032033 0.0753126892773911
};
\addlegendentry{n=20};

\end{axis}
\end{tikzpicture}%
  \begin{document}

  \begin{figure}[!ht]
  \centering\makebox[\textwidth]
  {\resizebox{1.2\textwidth}{!}{%
  \begin{tabularx}{1.2\textwidth}{*2X}
  \begin{center}
  \subfloat[Normal distribution at n=5,10,15,20]{\label{fig:normpdf_3d}}
  \subfloat[Probability frequency density plot at n=5,10,15,20]{\label{fig:normpdf_2d}}
  \end{center}
  \end{tabularx}}}
  \smallskip
  \caption{PDF and scatter plots}
  \label{fig:normpdf}
  \end{figure}


\end{document}
hpesoj626
  • 17,282
HCAI
  • 3,325

1 Answers1

6

Your posted example runs without error although it isn't an example of the case mentioned in the title of using \input in tabularx (which should work mostly, depending on what exactly you input).

However I can't really suggest changes as it is hard to guess the intention of the code. I make some suggestions below.

  \begin{figure}[!ht]

using ht prevents the use of page floats p so increases the chance of this float going to the end of the document.

  \centering\makebox[\textwidth]

Since you make a box that is full width; center left or right adjustment has no affect as there is no adjustment possible. so \centering is doing nothing here and \makebox also does nothing as the contents of the box are fixed size.

  {\resizebox{1.2\textwidth}{!}{%

Scaling a table to fit is really a last resort as it produces inconsistent font sizes, however in this case you are scaling to 1.2 textwidth a table that is itself forced to 1.2 textwidth so this has no affect (other than adding unneeded scaling code into the output)

  \begin{tabularx}{1.2\textwidth}{*2X}

OK I suppose although it is really better to use tabular* for this kind of rigid content. tabularx sets the content multiple times to find the best column widths but that is slow and unnecessary here as the result is necessarily that the width of the X columns is known in advance as (1.2\textwidth)-4\tabcolsep)/2 (It is not clear why you want the table to be wider than \textwidth)

  \begin{center}
  \subfloat[Normal distribution at n=5,10,15,20]{\label{fig:normpdf_3d}}
  \subfloat[Probability frequency density plot at n=5,10,15,20]{\label{fig:normpdf_2d}}
  \end{center}

Is there a & missing here, both these subfloats are in the first column.

  \end{tabularx}}}
David Carlisle
  • 757,742
  • Many thanks for your suggestions. The table presumably needs to be wider than textwidth because the images otherwise are too large for page and cause overfull boxes. Do you think the sizes should be manually tweaked in the external .tikz files? or is there a way of making sure they are correctly resized within main.tex? Ie so that the table is effectively at most \textwidth – HCAI Mar 28 '13 at 10:18
  • @HCAI You could resize each of the images separately as you include them (to say .45\textwidth) hard to say without seeing, but if you just make a box 1.2\textwidth wide it will not center, it will complain about being over-full and put all the extra width into the right margin, you would need to use some negative glue on the left margin to back it up by .1\textwidth if you want it to stick .1\textwidth into each margin. – David Carlisle Mar 28 '13 at 10:32
  • Yes I see what you mean, but where do you put the .1\textwidth in the above figure environment to force this -ve glue? – HCAI Mar 28 '13 at 10:48
  • 1
    I think you just want no table at all and \makebox[\textwidth]{\subfloat[...]{...}\hspace{2em}\subfloat[]{...}} – David Carlisle Mar 28 '13 at 11:12
  • Ah oh, I see, sounds reasonable, I can't remember now why I was trying to use a table now anyway. It's from copying and pasting answers on this forum, because I know they are from experts. I spend sooooooo much time typesetting stuff rather than writing. And although this is pleasing sometimes I wonder if it's worth it...:) – HCAI Mar 28 '13 at 11:34