使用 minpage 时将 pgfplots 拟合到边距内

使用 minpage 时将 pgfplots 拟合到边距内

我有以下代码。

\documentclass{report}
\usepackage[utf8]{inputenc}     % utf8 characters
%\usepackage[spanish]{babel}
\usepackage{amsmath}            % math packages
\usepackage{amsfonts}   
\usepackage{amssymb}
\usepackage{siunitx}            % SI units
\usepackage{tikz, pgfplots}     % TikZ 
\usepackage{circuitikz}
\usepackage{hyperref}           % links and hyperrefs
\usepackage{geometry}           % document size 
\usepackage{float, newfloat}    % floating environements
\usepackage[bottom]{footmisc}   % footnotes bottom fix
\usepackage{tocbibind}          % extra items to toc    
\usepackage{listings}           % listings  
\usepackage{fancyhdr}           % headers and footers   
\usepackage{standalone}         
\usepackage{emptypage}          % no numbers on empty pages
\usepackage{lipsum} 
\usepackage{booktabs}           % tables
\usepackage{tabularx}
\usepackage{glossaries}         % glossaries
\usepackage{subcaption}
\begin{document}

The second definition does not distinguish between the cell's short-circuit power and the component of switching power that is being dissipated internally to the cell as a result of the drain-to-substrate capacitance that is being charged and discharged. In this definition, the interconnect switching power is the power dissipated because of lumped wire capacitance and input pin capacitances but not because of the output pin capacitance.
    \begin{figure}[H]
        \centering
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
            \draw (0,0) node[left] {$V\subb{in}$} --++ (1,0) coordinate (e) --++ (0,-1) --++ (1,0) node[nmos, anchor=G] (nmos) {}
            (e) to[short,*-] ++ (0, 1) --++ (1,0) node[pmos, anchor=G] (pmos) {} (pmos.D) -- (nmos.D) (nmos.S) node[ground]{} (pmos.S) node[vcc]{}
            ($(nmos.D)!0.5!(pmos.D)$)  coordinate (out) to[short,*-] ++(1,0) node[right] {$V\subb{out}$};
%           (out)++(1,0) coordinate(en) to[C,*-,l=$C\subb{L}$] (en|-nmos.S) node[ground]{};
            \draw[-latex](pmos.S)++(.2,0) coordinate(ne) -- (ne|-pmos.D) node[midway,right] {$I\subb{DD}$};
            \end{tikzpicture}
        \end{minipage}%
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
                \begin{axis}[
                    width=\linewidth,
                    trim axis left, trim axis right,
                    xlabel=$t / \si{\nano\second}$,ylabel=$\si{\volt}$,
                    grid=both, minor tick num = 2,
                    axis y line*=left,
                    minor grid style = {dashed},
                    no markers,
                ]
                \addplot[blue,  thick] table[x index=0, y index=1,col sep= comma] {inversor_waveforms.data};%
                \label{p1}\addlegendentry{$V\subb{in}$}
                \addplot[red,   thick] table[x index=0, y index=2,col sep= comma] {inversor_waveforms.data};%
                \label{p2}\addlegendentry{$V\subb{out}$}            
                \end{axis}          
                \begin{axis}[
                    width=\linewidth,
    %               xlabel=$t/\si{\second}$,
                    ylabel=$\si{\nano\ampere}$,
                    axis y line*=right,
                    axis x line=none,
                    no markers,
                ]
                \addlegendimage{blue,thick}\addlegendentry{$V\subb{in}$}
                \addlegendimage{red, thick}\addlegendentry{$V\subb{out}$}
                \addplot[color=green!75!black,  thick] table[x index=0, y index=3,col sep= comma] {inversor_waveforms.data};\addlegendentry{$I\subb{DD}$}
                \end{axis}
                \end{tikzpicture}
        \end{minipage}
    \caption{CMOS inversor with voltage and current waveforms}
    \label{fig:inversor_ex}
    \end{figure}
    \hrule
    A simple example of short-circuit power can be seen in Figure \ref{fig:inversor_ex}. When the input voltage starts to fall the P-transistor begins to conduct while the N-transistor is transitioning between ohmic and cutoff region. The coexistence of the two partially-conducting transistors creates a direct path between \vdd\ and GND and thus consuming power. This effect is included in both definitions for internal power.
\end{document}

这给了我这个输出。 在此处输入图片描述 我怎样才能让情节适合边缘?

答案1

最常见的解决方案和我的建议(在文档内描述):

附言:另外,您的 MWE 和我的 MWE 中实际上并不需要 minipages,但我的答案也是为使用 minipages 而创建的(如果您出于任何原因确实需要它们)。如果您不使用 minipages,则必须更改某些长度,例如(\linewidth->0.5\linewidth 等)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{adjustbox}
\begin{document}

\section{The source of the problem}

As you can see in figure~\ref{fig:1} there is no blue border for the left part of the image 
\begin{figure}[!htb]
        \centering
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
            \path[draw,ultra thick,blue,fill=green] (0,0)rectangle(7,3)
            node[pos=0.5]{Text};
            \end{tikzpicture}
        \end{minipage}%
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
 \draw[fill=red] (0,0)rectangle(7,6);
                \end{tikzpicture}
        \end{minipage}
    \caption{CMOS inversor with voltage and current waveforms}
    \label{fig:1}
    \end{figure}

    If we reduce the width of the left image to 6 (instead 7 ) units:
\begin{figure}[!htb]
        \centering
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
            \draw[ultra thick,blue,fill=green] (0,0)rectangle(6,3)
            node[pos=0.5]{Text};
            \end{tikzpicture}
        \end{minipage}%
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
 \draw[fill=red] (0,0)rectangle(7,6);
                \end{tikzpicture}
        \end{minipage}
    \caption{CMOS inversor with voltage and current waveforms}
    \label{fig:2}
    \end{figure}

This means that our image extends out of minipage, that its role is not to prevent "overflowing" of its content.
\pagebreak
\section{Common solutions}

\subsection{Scaling}

 Scale the tikzpicture (see ~\ref{fig:3}):

\begin{figure}[!htb]
        \centering
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}[scale={6/7}]
            \draw[ultra thick,blue,fill=green] (0,0)rectangle(7,3)
            node[pos=0.5]{Text};
            \end{tikzpicture}
        \end{minipage}%
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
 \draw[fill=red] (0,0)rectangle(7,6);
                \end{tikzpicture}
        \end{minipage}
    \caption{CMOS inversor with voltage and current waveforms}
    \label{fig:3}
    \end{figure}

        Advantages:
    \begin{itemize}
        \item Text inside tikzpicture with original sizes 
    \end{itemize}

        Disadvantages:
    \begin{itemize}
        \item Need to scale every tikzpicture with separate scale number.
    \end{itemize}
\pagebreak
\subsection{The ``adjustbox''}
 Place the tikzpicture inside an adjustbox:

\begin{figure}[!htb]
        \centering
        \begin{minipage}{.5\linewidth}
\centering
\begin{adjustbox}{width=\textwidth}\begin{tikzpicture}
            \draw[ultra thick,blue,fill=green] (0,0)rectangle(7,3)
            node[pos=0.5]{Text};;
            \end{tikzpicture}
            \end{adjustbox}
        \end{minipage}%
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
 \draw[fill=red] (0,0)rectangle(7,6);
                \end{tikzpicture}
        \end{minipage}
    \caption{CMOS inversor with voltage and current waveforms}
    \label{fig:4}
    \end{figure}

    Advantages:
    \begin{itemize}
        \item Automating scale for every possibly picture
    \end{itemize}

        Disadvantages:
    \begin{itemize}
        \item Text is scaled too and picture fontsizes doesn't match text fontsize
        \item Usage of the extra package ``adjustbox''
    \end{itemize}

\pagebreak
\section{Suggests}
\subsection{In case of known maximum and minimum x coordinate}

{\bfseries Define a maximum x to be \verb|\linewidth| and use it as your basic unit}

\begin{figure}[!htb]
        \centering
        \begin{minipage}[inner sep=0]{.5\linewidth}
\centering
%Defining maximum x to be \linewidth:
\def\maxx{0.95\linewidth} %Reduced because of the thick width of
% the blue lines added an the result (Can be calculated, but also shows the mentioned disadvantages)
\begin{tikzpicture}
            \draw[ultra thick,blue,fill=green] (0,0)rectangle(\maxx,{3/7*\maxx})
            node[pos=0.5]{Text};;
            \end{tikzpicture}
        \end{minipage}%
        \begin{minipage}{.5\linewidth}
            \centering
            \begin{tikzpicture}
 \draw[fill=red] (0,0)rectangle(7,6);
                \end{tikzpicture}
        \end{minipage}
    \caption{CMOS inversor with voltage and current waveforms}
    \label{fig:5}
    \end{figure}

    Advantages:
    \begin{itemize}
        \item Everything is automated in your tikzpicture and canm be used in any document, any scale, any size etc.
        \item You can use the same idea for ymax and can transform the whole tikzpicture (plus xscale and yscale) with perfect results.
        \item Need more effort :P (Don't ask, I Used to teach)
    \end{itemize}

        Disadvantages:
    \begin{itemize}
        \item Need more time.
        \item Some times it is too complicated and may be ``impposible''.
    \end{itemize}
\end{document}

相关内容