0

I have been trying to insert an image to my LaTeX test book so I can further experiment with it, but the only thing which I see is the file path's name. I have tried some proposed solutions on both stackoverflow and other websites, but none worked -- what am I missing?

What I have tried:

  1. Including the image as follows:
\begin{figure}[h] 
    \centering
    \includegraphics[width=0.25\textwidth]{Plot}
    \caption{$J(\theta_0, \theta_1)$ as regards to $\theta_0$ and $\theta_1$}
    \label{fig:Fig1}
\end{figure}
  1. Instead of Plot in the previouds code, use Plot.png

  2. Removing the \graphicspath{ {Images/} } line

Notes:

  1. The image (Plot.png) is in the folder Image.

  2. I use overleaf, however, the overleaf's sample from the official website worked as a charm.

Full code:

\documentclass[12pt, letterpaper]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage[utf8]{amsmath, amssymb}
\graphicspath{ {Images/} }

\title{LINEAR REGRESSION IN DETAIL}
\author{Alexandros Voliotis \thanks{University of Thessaly}}
\date{May 2020}

\begin{document}

\maketitle
Test title of my first \textbf{ \LaTeX} document!


Italics: \textit{test}

Underline: \underline{test}


\chapter{Chapter 1}

\section{Introduction}

In the gradient descent algorithm we are trying to minimize the value of $J(\theta_0, \theta_1)$ for some $\theta_0, \theta_1 \in \mathbb{R}$.

This is quite tough to achieve in a few steps, however it is not entirely impossible. In order to make $J(\theta_0, \theta_1)$ equal to $0$, we must first set the step variable accordingly, and measure every time the output. This process should, and will, create a table with two columns as shown below:
\begin{itemize}
  \item 1\textsuperscript{st} column -- The values for the step variable.
  \item 2\textsuperscript{nd} column -- The values for the total tries variable.

\end{itemize}


A better visualization of the function $J(\theta_0, \theta_1)$ is as follows:

\begin{figure}[h] 
    \centering
    \includegraphics[width=0.25\textwidth]{Plot}
    \caption{$J(\theta_0, \theta_1)$ as regards to $\theta_0$ and $\theta_1$}
    \label{fig:Fig1}
\end{figure}
\end{document}
1

Fast answer: include \usepackage{float} and use [H] instead of [h]

Explained answer: There's the errors or recommendations that I have founded:

  1. Use lowercase letters for labels, path of folders, and others that usually refers object. For example use \label{tbl:its an example} instead of \label{tbl:Its An Example}. Why? because usually we forgot uppercase letters.
  2. Include \usepackage{float} to use [H] or [h] in \begin{figure}[H] on your documents.
  3. Use \usepackage{amsmath} \usepackage{amssymb} instead of your code if you have no errors with this.

I fixed some common errors in the code below:

\documentclass[12pt, letterpaper]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{float} % For placement of figures, tables, and other objects
\graphicspath{{imagesfolder/}} % use lowercase to avoid errors for typing

\title{LINEAR REGRESSION IN DETAIL}
\author{Alexandros Voliotis \thanks{University of Thessaly}}
\date{May 2020}

\begin{document}

\maketitle
Test title of my first \textbf{ \LaTeX} document!


Italics: \textit{test}

Underline: \underline{test}


\chapter{Mathematics}

\section{Introduction}

In the gradient descent algorithm we are trying to minimize the value of $J(\theta_0, \theta_1)$ for some $\theta_0, \theta_1 \in \mathbb{R}$.

This is quite tough to achieve in a few steps, however it is not entirely impossible. In order to make $J(\theta_0, \theta_1)$ equal to $0$, we must first set the step variable accordingly, and measure every time the output. This process should, and will, create a table with two columns as shown below:
\begin{itemize}
  \item 1\textsuperscript{st} column -- The values for the step variable.
  \item 2\textsuperscript{nd} column -- The values for the total tries variable.

\end{itemize}


A better visualization of the function $ J(\theta_0, \theta_1) $ is as follows (\ref{fig:figure 1}):

\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\textwidth]{image.png}
    \caption{$ J(\theta_0, \theta_1) $ as regards to $\ theta_0 $ and $ \theta_1 $}
    \label{fig:figure 1}
\end{figure}

\end{document}

enter image description here

2
  • Thanks for your input! I managed to solve this problem by actually switching the compile mode from "fast" to "normal" -- even your code wouldn't run without this change. However, it would be great if you could expand a bit more on why I would need to use the float package, and if I could utilise \floatplacement for more efficiency or better graphing (I guess?). – Alexander Voliotis May 10 '20 at 0:00
  • Ohh I see, it's necessary because LaTeX recognizes "tables" and "figures" as floats objects Full documentation here – Pablo Díaz May 10 '20 at 2:04

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.