1

Using this code:

    \documentclass{article}
    \usepackage{parskip}
    \usepackage[margin=.5cm]{geometry}
    \usepackage{makeidx}
    \usepackage{paralist}
    \usepackage{amsmath,amssymb}
    \usepackage{mdwtab}
    \usepackage{graphicx,subfigure}
    \DeclareMathSymbol{,}{\mathord}{letters}{"3B}
    \newcommand{\np}{\newpage}
    \begin{document}

\begin{figure}  
$$
\sigma( w^T x + b) = \frac{1}{1 + e^{-(w^T x + b)}}
$$
\vspace*{-7mm}
\caption{Sigmoid function}
\end{figure}

\begin{figure}  
$$
J = -\frac{1}{m}\sum_{i=1}^{m}y^{(i)}\log(a^{(i)})+(1-y^{(i)})\log(1-a^{(i)})
$$
\vspace*{-7mm}
\caption{Cost function}
\end{figure}

\begin{figure}
$$
J = \overline{J}
$$
\vspace*{-7mm}
\caption{Take mean of J}
\end{figure}

    \title{ \LaTeX\\
    }
    \author{\textbf{\Large }\\
        \textbf{\Large }
    }
    \maketitle
    \thispagestyle{empty}
    \np
    \tableofcontents
    \np
    \end{document}

renders third figure:

\begin{figure}
$$
J = \overline{J}
$$
\vspace*{-7mm}
\caption{Take mean of J}
\end{figure}

on second page of generated pdf document despite there being ample space available on current page for figure 3.

How can I amend my code so that all figures use max amount of space available on page?

Update :

Have tried using \begin{equation} , \end{equation} as suggested in comments

:

  \documentclass{article}
    \usepackage{parskip}
    \usepackage[margin=.5cm]{geometry}
    \usepackage{makeidx}
    \usepackage{paralist}
    \usepackage{amsmath,amssymb}
    \usepackage{mdwtab}
    \usepackage{graphicx,subfigure}
    \DeclareMathSymbol{,}{\mathord}{letters}{"3B}
    \newcommand{\np}{\newpage}
    \begin{document}

\begin{equation}  
$$
\sigma( w^T x + b) = \frac{1}{1 + e^{-(w^T x + b)}}
$$
\vspace*{-7mm}
\caption{Sigmoid function}
\end{equation} 

\begin{equation} 
$$
J = -\frac{1}{m}\sum_{i=1}^{m}y^{(i)}\log(a^{(i)})+(1-y^{(i)})\log(1-a^{(i)})
$$
\vspace*{-7mm}
\caption{Cost function}
\end{equation} 

\begin{equation} 
$$
J = \overline{J}
$$
\vspace*{-7mm}
\caption{Take mean of J}
\end{equation} 

    \title{ \LaTeX\\
    }
    \author{\textbf{\Large }\\
        \textbf{\Large }
    }
    \maketitle
    \thispagestyle{empty}
    \np
    \tableofcontents
    \np
    \end{document}

but returns error :

enter image description here

Have also tried \[ \] but same error.

The $ symbol is defined within math expressions correctly ?

I'm using mactex (http://www.tug.org/mactex/) with TexShop (http://pages.uoregon.edu/koch/texshop/)

blue-sky
  • 217

2 Answers2

3

If you really must use a figure environment, use just one, not three separate ones.

However, I suspect you'll be better off not using a floating environment, such as a figure, at all. Instead, consider loading the amsmath package and using a gather* environment.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for "gather*" env. and "\tag*" macro
\begin{document}

\begin{figure}[h]
\[
\sigma( w^T\!x + b) = \frac{1}{1 + e^{-(w^T\!x + b)}}
\]
\caption{Sigmoid function}

\bigskip
\[
J = -\frac{1}{m} \sum_{i=1}^{m}
\bigl[y^{(i)}\log(a^{(i)})+(1-y^{(i)})\log(1-a^{(i)})\bigr]
\]
\caption{Cost function}

\bigskip
\[
J = \overline{J}
\]
\caption{Take mean of J}
\end{figure}

\hrule

\begin{gather*}
\sigma( w^T\!x + b) = \frac{1}{1 + e^{-(w^T\!x + b)}}
\tag*{Sigmoid function} \\
J = -\frac{1}{m} \sum_{i=1}^{m}
\bigl[y^{(i)}\log(a^{(i)})+(1-y^{(i)})\log(1-a^{(i)})\bigr]
\tag*{Cost function} \\
J = \overline{J}
\tag*{Take mean of $J$}
\end{gather*}

\end{document} 
Mico
  • 506,678
  • will use gather instead, can each caption be aligned to right of each formula ? Currently it's aligned right to page of each formula. – blue-sky Nov 29 '17 at 09:18
  • @blue-sky - Sure, just replace each instance of \tag* with \quad\text. – Mico Nov 29 '17 at 09:20
  • 1
    @blue-sky - By the way, did you notice I inserted a pair of square brackets in the middle formula? – Mico Nov 29 '17 at 09:21
0

Thanks to comments, this appears to achieve expected result :

\documentclass{article}
    \usepackage{parskip}
    \usepackage[margin=.5cm]{geometry}
    \usepackage{makeidx}
    \usepackage{paralist}
    \usepackage{amsmath,amssymb}
    \usepackage{mdwtab}
    \usepackage{graphicx,subfigure}
    \DeclareMathSymbol{,}{\mathord}{letters}{"3B}
    \newcommand{\np}{\newpage}
    \begin{document}

\begin{equation}  
\sigma( w^T x + b) = \frac{1}{1 + e^{-(w^T x + b)}}
\text Sigmoid
\end{equation} 

\begin{equation} 
J = -\frac{1}{m}\sum_{i=1}^{m}y^{(i)}\log(a^{(i)})+(1-y^{(i)})\log(1-a^{(i)})
\text Cost
\end{equation} 

\begin{equation} 
J = \overline{J}
\text Mean
\end{equation} 

    \title{ \LaTeX\\
    }
    \author{\textbf{\Large }\\
        \textbf{\Large }
    }
    \maketitle
    \thispagestyle{empty}
    \np
    \tableofcontents
    \np
    \end{document}
blue-sky
  • 217