我一直试图将图像插入我的 LaTeX 测试书中,以便进一步进行实验,但我唯一看到的是文件路径的名称。我尝试了 stackoverflow 和其他网站上提出的一些解决方案,但都没有奏效——我错过了什么?
我已尝试过:
- 包括如下图像:
\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}
不要使用前面代码中的 Plot,而是使用
Plot.png
删除该
\graphicspath{ {Images/} }
行
笔记:
图像(Plot.png)位于 Image 文件夹中。
我使用 overleaf,然而,官方网站上的 overleaf 示例非常有效。
完整代码:
\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
快速回答:包括\usepackage{float}
并使用[H]
而不是[h]
解释性回答:以下是我发现的错误或建议:
- 标签、文件夹路径和其他通常指代对象的字母请使用小写字母。例如,使用
\label{tbl:its an example}
而不是\label{tbl:Its An Example}
。为什么?因为我们通常会忘记大写字母。 - 包括
\usepackage{float}
使用[H]
或[h]
包含\begin{figure}[H]
在您的文档中。 \usepackage{amsmath}
\usepackage{amssymb}
如果此操作没有错误,则使用它代替您的代码。
我修复了以下代码中的一些常见错误:
\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}