Latex 更新命令无法正常工作

发布于 2024-08-30 06:53:14 字数 2188 浏览 1 评论 0原文

为什么这不起作用:

\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

{绿色}测试{3}{section.1}

如何才能使其正常工作?

Why is this not working:

\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 Error: Something's
wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX
Companion for explanation. Type H
for immediate help. ...

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

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

How can I make it work properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羁〃客ぐ 2024-09-06 06:53:14

您应该尝试将代码压缩为 最小示例,那么您要么您自己找出错误,否则我们可以更好地帮助您。我认为上面的所有代码都是不必要的。

You should try to condense your code down to a minimal example, then either you're getting to your error yourself or we can help you a bit better. i don't think that all the code above is necessary.

在风中等你 2024-09-06 06:53:14

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

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

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

}

which 没有正确完成 - breaklines=true, 中的逗号放错了位置。然而,一旦我删除了该逗号并注释掉了 \includegraphics 语句,该文件就被毫无抱怨地处理了。这更加坚定了我的信念,即错误不在我们的 renewcommand 宏中。

I inserted your \renewcommand into one of my LaTeX files and it worked fine, though I have questions about your aesthetic choices. This leads me to think that your error arises when you use the redefined macro. But your question does not really show us that. Or, that the error occurs before your use of the macro but that LaTeX doesn't notice until it executes the macro and fails.

EDIT: OK, I copied your text into an empty document and tried to process it. My system complained about

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

}

which does not finish properly -- the comma in breaklines=true, is misplaced. However once I had removed that comma and commented out the \includegraphics statements the file was processed without complaint. This reinforces my belief that the error is not in our renewcommand macro.

山色无中 2024-09-06 06:53:14

这是一份已经交付的项目报告,我不会再费心了,至少现在是这样,因为我现在有更重要的事情要处理。

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

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

This was for a project report already delivered and I'm not going to bother with it anymore, at least for now cause I have more important things to deal with at the moment.

I "fixed" it by using \newcommand instead and created my own commands to replace \section, \subsection and it was basically a case of find/replace. It's not the best solution as I like to use whatever is there already and configure it accordingly, but it will do for now...

I'll revisit this problem in the future if I need too. I appreciate everyone's input.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文