Equations system with a black rectangle in LaTeX

栏目: IT技术 · 发布时间: 4年前

► Versión en Español

A friend sent me a file in LaTeX that she had received. When compiling it, one of the equations had a strange black rectangle:

Equations system with a black rectangle in LaTeX

The file was about 20 pages long. After minimizing and minimizing the file, I got this simplified version:

\documentclass[12pt]{article}

\usepackage[table]{xcolor}

\begin{document}

\centering

Some initial text.

\[

  \begin{array}{c}

    \rowcolor{red}

      1 + 2 = 3 \\

    \rowcolor{green}

      1 + 2 = 3 \\

    \rowcolor{blue}

  \end{array}

\]

Some random two pages of text here \\

just to make debugging difficult.

\[

  \left\{

    \begin{array}{rrrrrrr}

       2x &+& y &+& 4z &=& 0\\

        x &+& 6y &+& 7z &=& 0\\

    \end{array}

  \right.

\]

Some final text.

\end{document}

Can you spot the error? In case you can't mentally compile LaTeX, the result is:

Equations system with a black rectangle in LaTeX

Now, is it easier to find the error?

[spoiler alert]

Well, the problem is in the previous table, it has the declaration of the color of the “last” row that does not exist. In the original version, it was a commented row, making it more difficult to spot. Moreover, between one table and the equations system there were one or two pages, making it more difficult to see that the error was actually caused by something that was much earlier than the position where it appeared.

\[

  \begin{array}{c}

    \rowcolor{red}

      1 + 2 = 3 \\

    \rowcolor{green}

      1 + 2 = 3 \\

    \rowcolor{blue}    % <---- the error is here

  \end{array}

\]

The strangest thing is that you get a black rectangle instead of a blue rectangle. I suppose some flag is set that says that there is something interesting in the next cell, but  the color is reset and that is why it is black. I've been looking at the xcolor package code, but my LaTeX-Fu is not strong enough. (It is not even clear to me if this is classified as a bug or not.) And furthermore, there is a workaround that is not to write LaTex with errors.


Bonus: The error is in the first part, so with a trivial change in the second part we can get a matrix or table with a strange black cell.

Equations system with a black rectangle in LaTeX

\begin{center}

  \begin{tabular}{|c|c| c|}

     \hline

      a  &  b  &  c  \\

     \hline

     $1$ & $2$ & $3$ \\

     \hline

  \end{tabular}

\end{center}


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

自制编译器

自制编译器

[日] 青木峰郎 / 严圣逸、绝云 / 人民邮电出版社 / 2016-6 / 99.00元

本书将带领读者从头开始制作一门语言的编译器。笔者特意为本书设计了CЬ语言,CЬ可以说是C语言的子集,实现了包括指针运算等在内的C语言的主要部分。本书所实现的编译器就是C Ь语言的编译器, 是实实在在的编译器,而非有诸多限制的玩具。另外,除编译器之外,本书对以编译器为中心的编程语言的运行环境,即编译器、汇编器、链接器、硬件、运行时环境等都有所提及,介绍了程序运行的所有环节。一起来看看 《自制编译器》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

html转js在线工具
html转js在线工具

html转js在线工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具