为什么将 \input 放入 tabularx 环境中无法编译?

为什么将 \input 放入 tabularx 环境中无法编译?

放一张 tikzpicturenormpdf_2d.tex

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

单独使用是没问题的。但是,将它放入\tabularx环境中则无法编译。为什么?此环境在工作之前需要了解哪些属性\input?大小/宽度?

不过这很好:

\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}

这不是:

\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}

答案1

\input您发布的示例运行时没有错误,尽管它不是使用标题中提到的案例的示例tabularx(这应该主要起作用,取决于您输入的具体内容)。

但是我无法真正提出修改建议,因为很难猜测代码的意图。我在下面提出了一些建议。

  \begin{figure}[!ht]

使用ht可防止使用页面浮动,p因此增加了该浮动到达文档末尾的机会。

  \centering\makebox[\textwidth]

由于您制作了一个全宽的盒子;因此中心左或右调整不会产生任何影响,因为无法进行调整。所以\centering这里什么也不做,而且\makebox由于盒子的内容是固定大小的,因此什么也不做。

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

缩放表格以适应实际上是最后的手段,因为它会产生不一致的字体大小,但是在这种情况下,您将表格缩放到 1.2 个文本宽度,而表格本身被强制为 1.2 个文本宽度,因此这没有影响(除了在输出中添加不需要的缩放代码)

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

tabular*好吧,我想虽然对于这种刚性内容来说, 使用它确实更好。tabularx多次设置内容以找到最佳列宽,但这很慢而且没有必要,因为结果必然是预先知道 X 列的宽度 (1.2\textwidth)-4\tabcolsep)/2 (不清楚为什么您希望表格比\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}

这里是否&缺少了什么,这两个子浮点数都在第一列。

  \end{tabularx}}}

相关内容