1

enter image description hereI am trying to align some text and a figure (pgfplots) together. I looked through some threads and found a nice package adjustbox which aligned the text and figure. However, by my example, the text is now too high. I would like to try to have them aligned straight across. I am not able to come up with a solution.

Any help would be appreciated. Here is my document.

\usepackage[utf8]{inputenc}
\usepackage[margin=.75in]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\rhead{AP Calculus AB}
\lhead{Mr. Bennett}
\chead{Limits and Continuity}
\cfoot{ Page \thepage}
\usepackage{adjustbox}
\usepackage{pgffor, ifthen}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.misc, positioning}
\usetikzlibrary{arrows,shapes,positioning,snakes}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\pgfplotsset{every x tick label/.append style={font=\tiny, yshift=0.5ex}}
\pgfplotsset{every y tick label/.append style={font=\tiny, xshift=0.5ex}}


 \newcommand{\s}{\small}
 \newcommand{\f}{\footnotesize}
 
 \newcommand{\notes}[3][\empty]{%
    \noindent \vspace{10pt}\\
    \foreach \n in {1,...,#2}{%
        \ifthenelse{\equal{#1}{\empty}}
            {\rule{#3}{0.5pt}\\}
            {\rule{#3}{0.5pt}\vspace{#1}\\}
        }
}


\begin{document}

    \adjustbox{valign=t}{\begin{minipage}{.5\textwidth}
    The equation of the function graphed to the right is \(f(x)=\dfrac{2x^2+7x+6}{x^2-4}\).  The coordinates of the hole in the graph are \(\bigg(2,\dfrac{1}{4}\bigg)\)
    \end{minipage}}
    \adjustbox{valign=t}{\begin{minipage}{.5\textwidth}
        \begin{tikzpicture}
            \begin{axis}
                [width=4in,
                    grid style={black!25},
                    axis x line = center,
                    axis y line = center,
                    xmin = -6,   xmax = 10,
                    ymin = -6,  ymax = 10,
                    xtick = {-6,-5,...,10},
                    ytick = {-6,-5,...,10},
                    xlabel={$x$},
                    ylabel={$y$},
                    xlabel style={above right},
                    ylabel style={above right},
                    axis line style={latex-latex},
                    grid=both
                ]
                        \addplot[thick,color=red,domain=2.2:10] {(2*x+3)/(x-2)};
                        \addplot[color=red,thick,domain=-6:1.99] {(2*x+3)/(x-2)};
            
                        \addplot[color=red,mark=*,fill=white,only marks] coordinates {(-2,.25)};
                        \addplot[dashed,thick, samples=50, smooth,domain=0:6,blue] coordinates {(2,-6)(2,10)};
                        \addplot[dashed,thick,samples=50,smooth,domain=-6:10,blue] coordinates {(-6,2)(10,2)};

            \end{axis}
        \end{tikzpicture}
    \end{minipage}}
    \vspace*{.25in}
    
    
    
    
    
\end{document}

1 Answer 1

1

You can get the following alignment without the use of the adjustbox package:

enter image description here

Colored rectangles are for demonstration purpose only (blue = text area, red = bounding box of the tikzpicture, green = minipage) and are not produced by this MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=.75in]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\rhead{AP Calculus AB}
\lhead{Mr. Bennett}
\chead{Limits and Continuity}
\cfoot{ Page \thepage}
\usepackage{adjustbox}
\usepackage{pgffor, ifthen}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.misc, positioning}
\usetikzlibrary{arrows,shapes,positioning,snakes}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\pgfplotsset{every x tick label/.append style={font=\tiny, yshift=0.5ex}}
\pgfplotsset{every y tick label/.append style={font=\tiny, xshift=0.5ex}}



 \newcommand{\s}{\small}
 \newcommand{\f}{\footnotesize}
 
 \newcommand{\notes}[3][\empty]{%
    \noindent \vspace{10pt}\\
    \foreach \n in {1,...,#2}{%
        \ifthenelse{\equal{#1}{\empty}}
            {\rule{#3}{0.5pt}\\}
            {\rule{#3}{0.5pt}\vspace{#1}\\}
        }
}


\newlength{\mylength}       
\settoheight{\mylength}{T}

\begin{document}

\noindent
\begin{minipage}[t]{.45\textwidth}
    The equation of the function graphed to the right is \(f(x)=\dfrac{2x^2+7x+6}{x^2-4}\).  The coordinates of the hole in the graph are \(\bigg(2,\dfrac{1}{4}\bigg)\)
    \end{minipage}
    \hfill
        \begin{tikzpicture}[baseline={([yshift=-\mylength]current bounding box.north)}]
            \begin{axis}
                [width=4in,
                    grid style={black!25},
                    axis x line = center,
                    axis y line = center,
                    xmin = -6,   xmax = 10,
                    ymin = -6,  ymax = 10,
                    xtick = {-6,-5,...,10},
                    ytick = {-6,-5,...,10},
                    xlabel={$x$},
                    ylabel={$y$},
                    xlabel style={above right},
                    ylabel style={above right},
                    axis line style={latex-latex},
                    grid=both
                ]
                        \addplot[thick,color=red,domain=2.2:10] {(2*x+3)/(x-2)};
                        \addplot[color=red,thick,domain=-6:1.99] {(2*x+3)/(x-2)};
            
                        \addplot[color=red,mark=*,fill=white,only marks] coordinates {(-2,.25)};
                        \addplot[dashed,thick, samples=50, smooth,domain=0:6,blue] coordinates {(2,-6)(2,10)};
                        \addplot[dashed,thick,samples=50,smooth,domain=-6:10,blue] coordinates {(-6,2)(10,2)};

            \end{axis};
        \end{tikzpicture}

    
    
    
    
    
\end{document}
5
  • Thank you so much!
    – Nick B
    May 22, 2022 at 1:27
  • does not seem to be working. I copied your example, but the text is now higher than the image.
    – Nick B
    May 22, 2022 at 10:12
  • @NickB: Would you mind sharing a screenshot of the output you get? A sketch of the desired alignment would also be useful.
    – leandriis
    May 22, 2022 at 11:10
  • posted above. Let me know if you can see it.
    – Nick B
    May 22, 2022 at 11:12
  • @NickB: That's exactly the same output I also included in my answer, I jut added the colored rectantgles in order to make the alignment more visible. What about the desired layout? Is the following closer to the expected output? i.stack.imgur.com/XSFTb.png
    – leandriis
    May 22, 2022 at 12:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .