[Tex/LaTex] How to automatically adjust subfigure width to textwidth?

floatssubcaption

Code where I have to manually adjust subfigure textwidth (here .95\textwidth) each time, but I would like do it automatically; you can use any enough big input image

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption}
\usepackage[export]{adjustbox}

\begin{document}

    \begin{figure}
    \centering
    \begin{subfigure}{.95\textwidth}
        \adjustbox{trim=0 .45\height{} 0 0, clip, width=1\textwidth}
        {\includegraphics[page=1]{{P100C1}.pdf}}
    \caption{P100 C1.}
    \end{subfigure}

     \begin{subfigure}{.95\textwidth}
        \adjustbox{trim=0 .45\height{} 0 0, clip, width=1\textwidth}
        {\includegraphics[page=1]{{P100C1}.pdf}}
    \caption{P100 C2.}
    \end{subfigure}
    \caption{Descriptive statistics of two lorem ipsun on long recordings lorem ipsun dataabess lorem ipsun lorem ipsun.}
    \end{figure}

\end{document}

Input image can be downloaded from Google Drive Share here or other hosting service here made by NCSS Statistics.

Output

LaTeX Warning: Float too large for page by 11.50876pt on input line 1950.

Testing David and Arash's proposals

\begin{figure}
\centering
\begin{subfigure}[a]{.85\textwidth}
   \includegraphics[page=2,width=\linewidth,keepaspectratio]{P100C1.pdf}
\caption{P100 C1.}
\end{subfigure}

\begin{subfigure}[b]{.85\textwidth}
   \includegraphics[page=2,width=\linewidth,keepaspectratio]{P100C2.pdf}
\caption{P100 C2.}
\end{subfigure}
\caption{Descriptive statistics of lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem.}
\end{figure}

Output: no warning

Automatic approach would be nice.

TeXLive: 2016
OS: Debian 8.5

Best Answer

Your modified write-up suggests that what you really need to do is to constrain the height of the graphs. Assuming your captions aren't overly long, setting the option height=0.4\textheight may work for you.

enter image description here

\documentclass[demo]{article} % remove 'demo' option in real document
\usepackage{graphicx,subcaption}
\begin{document}

\begin{figure}

\begin{subfigure}{\textwidth}
\centering
\includegraphics[page=2,width=0.85\textwidth,
                    height=0.4\textheight,
                    keepaspectratio]{P100C1.pdf}
\caption{P100 C1.}
\end{subfigure}

\bigskip
\begin{subfigure}{\textwidth}
\centering
\includegraphics[page=2,width=0.85\textwidth,
                    height=0.4\textheight,
                    keepaspectratio]{P100C2.pdf}
\caption{P100 C2.}
\end{subfigure}

\caption{Descriptive statistics of lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem.}
\end{figure}

\end{document}
Related Question