2

I want to center my two subfigures under the enumeration item, while the figure output is just at the center of the page.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{subfig}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{enumerate}
\item 11111
    \begin{enumerate}
    \item Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test 

    \begin{figure}[ht]
    \centering
\subfloat[Even function:reflectional symmetry   \label{a}]%
{
\begin{tikzpicture}
    \begin{axis}[width=0.3\linewidth, ymax=2.5,ymin=-0.5]
    \addplot[domain=-5:5, color=red,samples=500]{cos(deg(x))+(cos(deg(x)))^2};
    \end{axis}
\end{tikzpicture}
}
    \hfil
\subfloat[Odd function: rotational symmetry \label{b}]%
{
\begin{tikzpicture}
    \begin{axis}[width=0.3\linewidth, ymax=1.5,ymin=-1.5]
    \addplot[domain=-3:3, color=red,samples=50]{0.1*x+(sin(deg(x)))^3};
    \end{axis}
\end{tikzpicture}
}
    \caption{ }
    \label{1}
    \end{figure}

\end{enumerate}

\item 22222
\end{enumerate}
\end{document}

By using the code above, the output is my output

I want it to be centered under the (a).

Like the picture below (made by Adobe PS)

enter image description here

*Part of the code was provided by @Zarko .

5
  • 1
    A figure is a floating environment. A minipage is not.
    – Denis
    Oct 12, 2017 at 14:39
  • 3
    You can't have floats inside a minipage (and it doesn't make sense to do so either). What were you trying to achieve? Edit: Note also that the subfigure package is considered deprecated, and that using the features of either the subfig or subcaption package is recommended instead. Oct 12, 2017 at 14:54
  • Thank you! @TorbjørnT. I want to center a figure with 2 subfigures under an intended item. How can I achieve
    – Siwei Feng
    Oct 12, 2017 at 15:02
  • @Superfrankie, please clarify your question with extension of your code snippet to complete small document beginning with \documentclass{...} and end{document}`.
    – Zarko
    Oct 12, 2017 at 15:16
  • also have a look at questions/55337.
    – Denis
    Oct 12, 2017 at 15:17

1 Answer 1

3

as mentioned in above comments:

  • floats had not be enclosed in minipages (or other environments)
  • for sub figures and tables are available packages sunfig (as used in *mwe* below) andsuncaption
  • that sub figures you can fit in one line, the sum of their widths had to be smaller than text width (therefore i add width=0.45\linewidth to each axis declaration)
  • red line only indicate page layout. showframe had to be removed in real document

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{subfig}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}[ht]
    \centering
\subfloat[Even function:reflectional symmetry   \label{a}]%
{
\begin{tikzpicture}
    \begin{axis}[width=0.45\linewidth, ymax=2.5,ymin=-0.5]
    \addplot[domain=-5:5, color=red,samples=500]{cos(deg(x))+(cos(deg(x)))^2};
    \end{axis}
\end{tikzpicture}
}
    \hfil
\subfloat[Odd function: rotational symmetry \label{b}]%
{
\begin{tikzpicture}
    \begin{axis}[width=0.45\linewidth, ymax=1.5,ymin=-1.5]
    \addplot[domain=-3:3, color=red,samples=50]{0.1*x+(sin(deg(x)))^3};
    \end{axis}
\end{tikzpicture}
}
    \caption{ }
    \label{1}
    \end{figure}
\end{document}

addendum:

after edited question is more clear where images should be:

enter image description here

are now correct positioned?

frame around image is only for show that images are now centered to enumerate list. in real document you should remove \fbox from code.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{subfig}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{enumerate}
\item 11111
    \begin{enumerate}
    \item Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test

    \begin{figure}[ht]
\hfill\fbox{
    \begin{minipage}{\dimexpr\linewidth-\leftmargin-\leftmargini\relax}
    \centering
\subfloat[Even function: reflectional symmetry   \label{a}]%
{
\begin{tikzpicture}
    \begin{axis}[width=0.48\linewidth, ymax=2.5,ymin=-0.5]
    \addplot[domain=-5:5, color=red,samples=500]{cos(deg(x))+(cos(deg(x)))^2};
    \end{axis}
\end{tikzpicture}
}
    \hfil
\subfloat[Odd function: rotational symmetry \label{b}]%
{
\begin{tikzpicture}
    \begin{axis}[width=0.48\linewidth, ymax=1.5,ymin=-1.5]
    \addplot[domain=-3:3, color=red,samples=50]{0.1*x+(sin(deg(x)))^3};
    \end{axis}
\end{tikzpicture}
}
    \caption{ }
    \label{1}
    \end{minipage}
    }
    \end{figure}
\end{enumerate}

\item 22222
\end{enumerate}
\end{document}
7
  • Thank you, but I want to center my figure under an item of enumeration.
    – Siwei Feng
    Oct 13, 2017 at 0:44
  • (i) in question you now use my code, but you give credits to another (respectable) member of site (ii) your question is slightly more clear, bur it is still unknown, what you like to obtain. images start at left text border, images are so small, that can be centered below "a", a list start at middle of text width? clarify, please.
    – Zarko
    Oct 13, 2017 at 1:27
  • Apology for my mistakes on the credits.
    – Siwei Feng
    Oct 13, 2017 at 1:32
  • @Superfrankie, see if solution addendum to my answer is o.k.
    – Zarko
    Oct 13, 2017 at 2:03
  • Great! That's what I want. Thank you! But how to achieve this without borders....
    – Siwei Feng
    Oct 13, 2017 at 2:34

You must log in to answer this question.

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