当一侧是逐字记录时,如何将两列表格中的图像居中?

当一侧是逐字记录时,如何将两列表格中的图像居中?

我很难找到正确的排版方式:我需要在页面的一侧逐字逐句地写上代码,并在页面的右侧显示输出(图像)。

我试过使用 minipage,但效果不好。我现在尝试使用有 2 列的表格。我将逐字文本放在左列,然后将图像放在右列。问题是对齐不正确。我尝试了所有我知道的用于\raisebox{-.5\height}m规范的技巧。

以下是 MWE 的输出:

Mathematica 图形

我希望它能够借助 Visio 和 paint.exe 显示如下(这是使用剪切/粘贴手动绘制的)

Mathematica 图形

以下是代码(使用图形的演示选项,因此它可以按原样工作)

\documentclass[11pt,notitlepage]{article}%
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage[demo]{graphicx}
\usepackage{epstopdf}%
\usepackage[margin={2cm}]{geometry}%
\usepackage{array}%for m option

\begin{document}

\begin{tabular}[c]{|p{4in}|p{3in}|}\hline
%   \begin{tabular}{|p{4in}|m{3in}|}\hline    %also tried this, same problem
\begin{Verbatim}[fontsize=\small]
Clear["Global`*"];
SetDirectory[NotebookDirectory[]]
sys = TransferFunctionModel[1/(s^2 + 2/10 s + 1), s];

yStep = Assuming[t > 0, 
  Simplify@OutputResponse[sys, UnitStep[t], t]];
yImpulse = Simplify@OutputResponse[sys,DiracDelta[t],t];
p = Grid[{
   {Plot[Evaluate@{yStep, yImpulse}, {t, 0, 50},
     PlotRange -> {{0, 50}, {-0.8, 2.0}},
     Frame -> True,
     FrameLabel -> {{"y(t)", None}, 
                   {t, "step and impulse reponse"}},
     GridLines -> Automatic,
     GridLinesStyle -> Dashed,
     ImageSize -> {300, 300},
     PlotStyle -> {Red, Black},
     AspectRatio -> 1]
    },
   {
    Row[{"step response=", Re@yStep}]
    },
   {Row[{"impulse response=", Re@yImpulse}]}
   }, Alignment -> Left, Frame -> True]

yStep

{1 - E^(-t/10) Cos[(3 Sqrt[11] t)/10] 
  - (
  E^(-t/10) Sin[(3 Sqrt[11] t)/10])/(3 Sqrt[11])}

yImpulse

{(10 E^(-t/10) HeavisideTheta[t] 
  Sin[(3 Sqrt[11] t)/10])/(3 Sqrt[11])}
\end{Verbatim}
&
\raisebox{-.5\height}{\includegraphics[width=3in,height=3in]{whatever}}
\\\hline
\end{tabular}

\end{document}

TexLive 2013,Linux

答案1

您可以使用m{<length>}列类型两个都列:

\documentclass[11pt,notitlepage]{article}%
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage[demo]{graphicx}
\usepackage{epstopdf}%
\usepackage[margin={2cm}]{geometry}%
\usepackage{array}%for m option

\begin{document}

\begin{tabular}[c]{|m{4in}|m{3in}|}\hline
\begin{Verbatim}[fontsize=\small]
Clear["Global`*"];
SetDirectory[NotebookDirectory[]]
sys = TransferFunctionModel[1/(s^2 + 2/10 s + 1), s];

yStep = Assuming[t > 0, 
  Simplify@OutputResponse[sys, UnitStep[t], t]];
yImpulse = Simplify@OutputResponse[sys,DiracDelta[t],t];
p = Grid[{
   {Plot[Evaluate@{yStep, yImpulse}, {t, 0, 50},
     PlotRange -> {{0, 50}, {-0.8, 2.0}},
     Frame -> True,
     FrameLabel -> {{"y(t)", None}, 
                   {t, "step and impulse reponse"}},
     GridLines -> Automatic,
     GridLinesStyle -> Dashed,
     ImageSize -> {300, 300},
     PlotStyle -> {Red, Black},
     AspectRatio -> 1]
    },
   {
    Row[{"step response=", Re@yStep}]
    },
   {Row[{"impulse response=", Re@yImpulse}]}
   }, Alignment -> Left, Frame -> True]

yStep

{1 - E^(-t/10) Cos[(3 Sqrt[11] t)/10] 
  - (
  E^(-t/10) Sin[(3 Sqrt[11] t)/10])/(3 Sqrt[11])}

yImpulse

{(10 E^(-t/10) HeavisideTheta[t] 
  Sin[(3 Sqrt[11] t)/10])/(3 Sqrt[11])}
\end{Verbatim}
&
\includegraphics[width=3in,height=3in]{whatever}
\\\hline
\end{tabular}

\end{document}

在此处输入图片描述

可以使用 来实现微调(如果需要)\raisebox

答案2

这是使用该包的解决方案verbatimbox。虽然我将列保留为p类型,但也可以c同样轻松地使用类型。

\documentclass[11pt,notitlepage]{article}%
%\usepackage{verbatim}
\usepackage{verbatimbox}
\usepackage[demo]{graphicx}
\usepackage{epstopdf}%
\usepackage[margin={2cm}]{geometry}%
\usepackage{array}%for m option

\begin{document}

\begin{verbbox}[\small]
Clear["Global`*"];
SetDirectory[NotebookDirectory[]]
sys = TransferFunctionModel[1/(s^2 + 2/10 s + 1), s];

yStep = Assuming[t > 0, 
  Simplify@OutputResponse[sys, UnitStep[t], t]];
yImpulse = Simplify@OutputResponse[sys,DiracDelta[t],t];
p = Grid[{
   {Plot[Evaluate@{yStep, yImpulse}, {t, 0, 50},
     PlotRange -> {{0, 50}, {-0.8, 2.0}},
     Frame -> True,
     FrameLabel -> {{"y(t)", None}, 
                   {t, "step and impulse reponse"}},
     GridLines -> Automatic,
     GridLinesStyle -> Dashed,
     ImageSize -> {300, 300},
     PlotStyle -> {Red, Black},
     AspectRatio -> 1]
    },
   {
    Row[{"step response=", Re@yStep}]
    },
   {Row[{"impulse response=", Re@yImpulse}]}
   }, Alignment -> Left, Frame -> True]

yStep

{1 - E^(-t/10) Cos[(3 Sqrt[11] t)/10] 
  - (
  E^(-t/10) Sin[(3 Sqrt[11] t)/10])/(3 Sqrt[11])}

yImpulse

{(10 E^(-t/10) HeavisideTheta[t] 
  Sin[(3 Sqrt[11] t)/10])/(3 Sqrt[11])}
\end{verbbox}
\begin{tabular}[c]{|p{4in}|p{3in}|}\hline
\theverbbox&
\raisebox{\dimexpr.5\ht\savedverbbox-.5\height}{\includegraphics[width=3in,height=3in]{whatever}}
\\\hline
\end{tabular}

\end{document}

在此处输入图片描述

相关内容