【问题标题】:Latex renewcommand not working properly乳胶更新命令无法正常工作
【发布时间】:2014-01-12 11:22:35
【问题描述】:

为什么这不起作用:

\documentclass[a4paper,10pt]{article}
\usepackage{a4wide}
\usepackage[T1]{fontenc}
\usepackage[portuguese]{babel}
\usepackage[latin1]{inputenc}
\usepackage{indentfirst}
\usepackage{listings}
\usepackage{fancyhdr}
\usepackage{url}
\usepackage[compat2,a4paper,left=25mm,right=25mm,bottom=15mm,top=20mm]{geometry}
\usepackage{color}
\usepackage[colorlinks]{hyperref}
\usepackage[pdftex]{graphicx}

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\pagestyle{fancy}

\fancyhead[L]{\small Laboratórios de Informática III}
\fancyhead[R]{\small Projecto 1 (Linguagem \textsf{C})}

\lstset{
    basicstyle=\ttfamily\footnotesize,
    showstringspaces=false,
    frame=single,
    tabsize=4,
    breaklines=true,

}

\definecolor{Section1}{rgb}{0.09,0.21,0.36}
\definecolor{Section2}{rgb}{0.21,0.37,0.56}
\definecolor{Section3}{rgb}{0.30,0.50,0.74}

\hypersetup{
    bookmarks=false,
    linkcolor=red,
    urlcolor=cyan,
}

\renewcommand{\section}[1]{\texorpdfstring{\color{green}#1}{#1}}

\parskip=6pt

\begin{document}

\begin{titlepage}

\begin{center}

\includegraphics[width=5cm]{./logo.jpg}\\[1cm]

\textsc{\LARGE Universidade do Minho}\\[1cm]

\textsc{\large Licenciatura em Engenharia Informática\\Laboratórios de Informática III}\\[1.5cm]

\rule{\linewidth}{0.5mm}\\[0.4cm]

\huge{\textbf{\textsc{Relatório do Projecto 1 (Linguagem C)}}}

\rule{\linewidth}{0.5mm}

\vfill

\begin{tabular}{c c}

    \includegraphics[width=3.5cm]{./nuno.jpg} & \includegraphics[width=3.5cm]{./ricardo.jpg} \\

    \textsc{\large{Nuno Mendes (51161)}} & \textsc{\large{Ricardo Amaral (48404)}} \\

\end{tabular}

\vfill

\large{\today}

\end{center}

\end{titlepage}

\tableofcontents

\newpage

\section{Introdução}

Lorem ipsum...

\newpage

\appendix

\section{\color{Section1}Diagrama das Estruturas de Dados}

\begin{center}
\includegraphics[width=16cm]{./Diagrama.pdf}
\end{center}

\end{document}

! LaTeX 错误:有些东西 错误——可能缺少 \item。

参见 LaTeX 手册或 LaTeX 解释的伴侣。 H型 寻求即时帮助。 ...

                                               l.2 ...rline {1}\color

{green}Teste}{3}{section.1}

我怎样才能让它正常工作?

【问题讨论】:

  • 你的括号怎么样?对于每一个打开,都有一个关闭,并且在正确的位置?那个“teste}”在我看来格格不入。
  • 我只在我的代码上这样使用它:\section{Teste}
  • 用“完整”示例更新问题。
  • 您的文件在这里没问题。请注意,我们无法运行该文件,因为它引用了我们系统上没有的图形。请不要发布我们无法通过简单的复制和粘贴运行的示例代码。您可以通过说\vrule width 16cm height 5cm 来模拟图形。我们不会将其打印出来 :-) 如果您已经替换了测试代码中的图形,请运行它并发布您在问题中得到的确切输出。
  • 在 superuser.com 网站上发帖可能会更好:)

标签: latex renewcommand


【解决方案1】:

您应该尝试将您的代码压缩为 minimal example,这样您要么自己解决错误,要么我们可以为您提供更好的帮助。我不认为上面的所有代码都是必要的。

【讨论】:

  • 将你的 lstset 更改为 \lstset{ basicstyle=\ttfamily\footnotesize, showstringspaces=false, frame=single, tabsize=4, breaklines=true} 使它对我来说可以编译...
  • 好吧,我似乎无法在 cmets 中发布 code-sn-ps。删除 \lststed-block 中的空白行,然后为我编译您的文档(在我删除了对不存在图像的所有引用并确保我的 MacTex 可以使用您的西班牙语字符之后......)
  • 它不能为我编译,空行是复制/粘贴问题,我的代码没有那个空行。但请阅读下面我的“答案”。还是谢谢。
  • 虽然我同意这一点,但同样,除非你有答案,否则你不应该回答这个问题。我认为这属于评论。我仍然认为问题应该更短。
【解决方案2】:

我将您的 \renewcommand 插入到我的一个 LaTeX 文件中,它运行良好,但我对您的审美选择有疑问。这使我认为当您使用重新定义的宏时会出现错误。但你的问题并没有真正向我们展示这一点。或者,错误发生在您使用宏之前,但 LaTeX 在执行宏并失败之前不会注意到。

编辑:好的,我将您的文本复制到一个空文档中并尝试处理它。我的系统抱怨

\lstset{
basicstyle=\ttfamily\footnotesize,
showstringspaces=false,
frame=single,
tabsize=4,
breaklines=true,

}

没有正确完成——breaklines=true, 中的逗号放错了位置。但是,一旦我删除了那个逗号并注释掉了 \includegraphics 语句,该文件就被毫无怨言地处理了。这加强了我的信念,即错误不在我们的 renewcommand 宏中。

【讨论】:

  • 在这种情况下,错误可能发生在其他地方。我建议你创建一个小的 LaTeX 文档来检查宏是否有效。
  • 用“完整”示例更新问题。
  • 实际上,renewcommand 并非应有的样子,在最小页面上(以便 renewcommand 起作用),TOC 没有正确生成。至少是我测试它的方式。
【解决方案3】:

这是针对已经提交的项目报告,我不会再为它烦恼,至少现在因为我现在有更重要的事情要处理。

我通过使用 \newcommand 来“修复”它,并创建了我自己的命令来替换 \section、\subsection,这基本上是查找/替换的情况。这不是最好的解决方案,因为我喜欢使用已经存在的任何东西并进行相应的配置,但它现在可以......

如果我也需要,我将来会重新讨论这个问题。感谢大家的意见。

【讨论】:

  • 这在 tex.stackexchange.com 上可能会更好
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多