定义图像位置的路径

定义图像位置的路径

我正在尝试设置一个带有文件位置的变量,但出现以下错误:

! Undefined control sequence.
\Url Error ->\url used in a moving argument. 

l.166 ...epaspectratio]{\MOFile}

在我的 tex 文件中我有:

\usepackage{textgreek}
\usepackage{textcomp}
\usepackage{xcolor,colortbl}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage[utf8]{inputenc}
\pagenumbering{roman}
\usepackage{fancyref}
\usepackage{nameref}
\usepackage{url}
\usepackage{enumerate}
\usepackage{parskip}
\usepackage{soul}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{2}
\usepackage{threeparttable}
\usepackage{geometry}
\usepackage{float}
\usepackage{booktabs}
\usepackage{hyperref}
\hypersetup{colorlinks=true,filecolor=green,urlcolor=blue,linkcolor=black}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern} %Type1-font for non-english texts and characters
\usepackage{graphicx} %%For loading graphic files
\usepackage{subfig} %%Subfigures inside a figure
\usepackage{eso-pic}
\usepackage{array}
\usepackage{placeins}
\usepackage{float}
\usepackage{slashbox,pict2e}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{changepage}

\input{Variables}

\begin{document}

\begin{adjustwidth}{0cm}{0cm}
    \tableofcontents %Table of contents
    \pagestyle{plain} 
    \setcounter{page}{1}

    \chapter{Info}
        \section{Timestep}
            \begin{figure}[H]
                \centering
                \includegraphics[width=11cm, keepaspectratio]{\MOFile}
                \caption{Histogram}
            \end{figure}

        \FloatBarrier   
\end{adjustwidth}
\end{document}

在 Variables.tex 中:

\def \MOFile{\path{C:\Users\y\Documents\temp_20171010120402\timestep.png}}

我找到了一些关于这个问题的信息,但无法解决。我以为把 \protect 放在 \path 前面就可以解决这个问题,但事实并非如此。将 \path 更改为 \url 也无济于事。

我该如何解决这个问题?

编辑1: 我将路径中的反斜杠改为正斜杠,但仍然出现错误:

\Url Error ->\url used in a moving argument. 

l.166 ...epaspectratio]{\MOFile}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Use of \protect doesn't match its definition.
\filename@base ...t \edef lmr{lmtt}\protect \xdef 
                                              \T1/lmr/m/n/10 {\T1/lmr/m/...
l.166 ...epaspectratio]{\MOFile}

If you say, e.g., `\def\a1{...}', then you must always
put `1' after `\a', since control sequence names are
made up of letters only. The macro here has not been
followed by the required stuff, so I'm ignoring it.

改变后的路径定义为:

\def \MOFile{\path{C:/Users/y/Documents/temp_20171010122638/timestep.png}}

答案1

您的路径错误,您/不应该使用\tex 路径,即使在 Windows 上也是如此。

并且不能做

\includegraphics[width=11cm, keepaspectratio]{\MOFile}

因为您不能使用没有的\includegraphics{\path{a/b.png}}语法。\includegraphics{/a/b.png}\path

因此直接使用路径,或者不要\path在定义中使用\MOfile

但如果你只使用

\includegraphics{timestep}

扩展.png名将被默认,并且只要文件位于 TeX 的输入路径中的任何地方,就会找到它。

相关内容