1

I have a graph of two lines. Below the y-axis and centered about the y-axis, I would like to put "Graph of lines in the case $e=f=1$" in a box. "Graph of lines" above "in the case $e=f=1$." Here is the code.

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{mathtools,array}

\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}



\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-8,xmax=8,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-5,ymax=6,
    restrict y to domain=-5:6,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    extra x ticks={2},
    extra x tick labels={$2$},
    extra y ticks={-1},
    extra y tick labels={$-1$},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[latex-latex,samples=201,domain=-8:8,blue] {-0.6 * x  + 0.2} node[anchor=south west, pos=0.75,font=\footnotesize]{$3x + 5y = 1$};
\addplot[latex-latex,samples=201,domain=-8:8,purple] {(-2/3) * x + 1/3} node[anchor=south west, pos=0.1,font=\footnotesize]{$2x + 3y = 1$};
\draw [fill] (2,-1) circle [radius=1.5pt] node[anchor=north east,font=\tiny]{$(2, \, -1)$};
\end{axis}
\end{tikzpicture}
\hspace*{\fill}


\end{document}
1

Not sure if I understood your question correctly, but you can provide extra textboxes using the \node command. You can place the node referring to pgfplots internal coordinate system, which is accessible via (axis description cs:x-coordinate,y-coordinate) where the lower left corner of your graph equals to (0,0).

After adding the node to your graph the textbox would be cut off at the lower part due to clipped axis. You can avoid this passing the clip=false option to the axis-environment. Additionally, I removed \hspace*{\fill} at the beginning and the end of your document.

This is what I got:

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{mathtools,array}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-8,xmax=8,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-5,ymax=6,
    restrict y to domain=-5:6,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    extra x ticks={2},
    extra x tick labels={$2$},
    extra y ticks={-1},
    extra y tick labels={$-1$},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west},
    clip=false  %prevent axis to clip "picture area" (otherwise text box will be cut off)
]
\addplot[latex-latex,samples=201,domain=-8:8,blue] {-0.6 * x  + 0.2} node[anchor=south west, pos=0.75,font=\footnotesize]{$3x + 5y = 1$};
\addplot[latex-latex,samples=201,domain=-8:8,purple] {(-2/3) * x + 1/3} node[anchor=south west, pos=0.1,font=\footnotesize]{$2x + 3y = 1$};
\draw [fill] (2,-1) circle [radius=1.5pt] node[anchor=north east,font=\tiny]{$(2, \, -1)$};
% add a node to provide a text box, use draw option to get a border line and align option to make \\ useable
\node[draw, align=center] at (axis description cs:0.5,-0.1) {Graph of lines \\ in the case $e=f=1$};
\end{axis}
\end{tikzpicture}

\end{document}

output

-- EDIT due to comment:

The bounding box is drawn because of the draw option passed to the \node command. You can change the font to footnotesize by passing font={\footnotesize} to \node aswell, which leads into

\node[draw, align=center, font={\footnotesize}] at (axis description cs:0.5,-0.1) {Graph of lines \\ in the case $e=f=1$};

The clip option influences the border of the "container" of your diagram. Nodes which are too close to the border will be cut of due to clip=true which is set by default, so there is no need to specify this in general. However, clip=false expands the "container" and as a result nodes close to the border will not be cut off. A legend of your diagram will not be cut of, too. In this case the border of your "container" is expanded automatically. The node containing your desired text is more likely an additional remark or comment, not a legend or caption.

To add a box to the node containing your coordinates (2, -1) you only need to pass draw to the node's options. So this line would be:

\draw [fill] (2,-1) circle [radius=1.5pt] node[draw, anchor=north east,font=\tiny]{$(2, \, -1)$};

All in all after editing the two given lines the output looks like:

output with additional bounding box and footnotsize font

  • Yes, that is what I wanted. I guess that this code gave me a centered box because I had the y-axis centered. Why is this node surrounded by a box? The node for the point (2,-1) is not surrounded by a box. How do I get the font in the box reduced to footnotesize? Are you saying that without the specification clip=false, any legend or any equation for the graph of a function that was close too close to the edges of the frame, as determined by the axes, would be obscured? Is there a specification clip=true? – user143462 Nov 23 '14 at 20:18
  • I edited my answer to explain how these things could be done... – albert Nov 23 '14 at 20:59
  • @albert Your graph is what I want. You didn't edit the code. – Adelyn Nov 25 '14 at 15:06
  • @albert This is the code that I have to get a smaller font for the caption to the graph. \node[draw, align=center, font={\footnotesize}] at (axis description cs:0.5,-0.1) {Graph of lines in \\ the case $e=f=1$}; It did not reduce the font. – user143462 Nov 25 '14 at 19:09
  • @user143462: This code snipped is working for me. Please keep in mind, that the text in the lower box is bigger than the text in the box showing your coordinates. The 'Graph of ...' text is \footnotesize, the text showing the coordinates '(2, -1)' is a bit smaller because of the font option set to \tiny there. – albert Nov 25 '14 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.