如何使用 LaTeX 在复杂的布局中组合代码列表和图形?

如何使用 LaTeX 在复杂的布局中组合代码列表和图形?

我尝试了很多方法但都没有成功,包括表格和子图。

我的目标是实现下面的布局,其中:

  • 灰色部分代表代码清单
  • 绘图矩形代表.pdf图形

这种布局最好是一张可以在整个手稿中引用并LaTeX可以为其分配编号的图。但是,即使是表格也可以。我唯一的限制是我必须使用\documentclass[man, a4paper, 12pt]{apa7},即apa7类,有时这会导致与其他包发生冲突。

我将非常感激任何能够帮助我理解如何使用 有效地实现此类布局的帮助LaTeX

在此处输入图片描述


编辑。根据以下评论和 Simon Dispa 的回答,我能够实现我想要的。我把这段代码留在这里作为参考,以防其他人对类似的东西感兴趣。

\documentclass[man, a4paper, 12pt]{apa7}
\usepackage{minted}
\usepackage{framed}

% Minted settings.
\setminted{fontsize=\footnotesize, baselinestretch=1.5}

% Required by `apa7'.
\shorttitle{}

\begin{document}

\begin{figure}
    \caption{Example caption.}
    \label{fig:layout}
    \begin{framed}
        \centering
        % Left side.
        \begin{minipage}[t]{.4\textwidth}
            \textbf{Code}
            \begin{minted}[autogobble]{R}
                # Load library.
                library(powerly)

                # Run the method.
                results <- powerly(
                    range_lower = 400,
                    range_upper = 1400,
                    samples = 20,
                    replications = 30,
                    measure = "sen",
                    measure_value = 0.6,
                    statistic = "power",
                    statistic_value = 0.8,
                    model = "ggm",
                    nodes = 10,
                    density = 0.4
                )
            \end{minted}

            \textbf{Output}
            \begin{minted}[autogobble]{R}
                # Show summary.
                summary(results)
            \end{minted}

            \begin{minted}[autogobble]{text}
                Method run (6.98 sec):
                - converged: yes
                - iterations: 1
                - recommendation: 834
            \end{minted}
        \end{minipage}
        \quad
        % Right side.
        \begin{minipage}[t]{.5\textwidth}
            \textbf{Plots}
            % Plot 1.
            \begin{minted}[autogobble]{R}
                plot(results, step = 1)
            \end{minted}
            \includegraphics[width=\linewidth, height=4.1cm]{example-image}

            % Plot 2.
            \begin{minted}[autogobble]{R}
                plot(results, step = 2)
            \end{minted}
            \includegraphics[width=\linewidth, height=4.1cm]{example-image}

            % Plot 3.
            \begin{minted}[autogobble]{R}
                plot(results, step = 3)
            \end{minted}
            \includegraphics[width=\linewidth, height=4.1cm]{example-image}
        \end{minipage}
    \end{framed}
    \figurenote {Example note.}
\end{figure}

\end{document}

结果:

在此处输入图片描述

答案1

从文件开始./samples/longsample.tex,从apa7分发中,我并排添加了两个小页面:左边是铸造的代码,右边是 3 张图片。

无需猜测使用\fitfigure

米

%%
%% This is file `./samples/longsample.tex',
%% apa7.dtx  (with options: `longsample')
%% ----------------------------------------------------------------------

\documentclass[man]{apa7}

\usepackage{lipsum}
\usepackage{minted}% added <<<<<

\usepackage[american]{babel}

\usepackage{csquotes}
\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
%\addbibresource{bibliography.bib}

\title{Sample APA-Style Document Using the \textsf{apa7} Package}
\shorttitle{Sample Document}

\author{Daniel A. Weiss}
\affiliation{A University Somewhere}

\leftheader{Weiss}

\abstract{\lipsum[1]}

\keywords{APA style, demonstration}

\authornote{
   \addORCIDlink{Daniel A. Weiss}{0000-0000-0000-0000}

  Correspondence concerning this article should be addressed to Daniel A. Weiss, Department of Educational Psychology, Counseling and
  Special Education, A University Somewhere, 123 Main St., Oneonta, NY
  13820.  E-mail: [email protected]}

\begin{document}
\maketitle
\lipsum[2]


\section{Method}
\subsection{Participants}
\lipsum[4]

\subsection{Materials}
\lipsum[5]

\subsection{Design}
\lipsum[6]

\subsection{Procedure}
\lipsum[7-8]

\begin{minipage}{0.45\textwidth}}% added <<<<<<<<
Code

\begin{minted}[autogobble]{R}
    results <- powerly(
    range_lower = 300,
    range_upper = 1500,
    samples = 30,
    replications = 20,
    measure = "sen",
    measure_value = 0.6,
    statistic = "power",
    statistic_value = 0.8,
    model = "ggm",
    nodes = 10,
    density = 0.4
    )
\end{minted}
\bigskip

Output

\begin{minted}[autogobble]{R}
    summary(results)
    # Method run (6.9773 sec):
    # - converged: yes
    # - iterations: 1
    # - recommendation: 50% = 615
\end{minted}
\end{minipage}
\begin{minipage}{0.45\textwidth}
% Plot 1.
\begin{minted}[autogobble]{R}
    plot(results, step = 1)
\end{minted}
    \label{fig:p1}
    \fitfigure{example-image}
% Plot 2.
\begin{minted}[autogobble]{R}
    plot(results, step = 2)
\end{minted}
    \label{fig:p2}
    \fitfigure{example-image}
% Plot 3.
\begin{minted}[autogobble]{R}
    plot(results, step = 1)
\end{minted}
    \label{fig:p3}
    \fitfigure{example-image}
\end{minipage}

\subsubsection{Instrument \#1}
\lipsum[8]

\paragraph{Reliability}
\lipsum[9]       

\end{document}

jou这是使用类选项(默认)的相同代码的输出

杰

相关内容