4

I'm a new user of TeX. I'm actually writing my first document. I started to type a basic equation and I want to colorize it in a box. Here is the code:

\documentclass{article}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsfonts}
\usepackage{color}

\begin{document}

\begin{center}
{\large \textbf{COMMENT RÉSOUDRE UNE ÉQUATION ?}}
\end{center}

\fcolorbox{brun}{chamois}{\parbox{\linewidth}
{\begin{center}
Résoudre l'équation (E): 
$(x^{2} + 1)^{2} = (x^ {2} - 1)^{2} 
$\ d'inconnue x $\in \mathbb{R} }
$\end{center}
\end{document}}

When I press F1, I got many errors regarding line 20? What's wrong?

Regards

  • 1
    Why is there a second } after \end{document} should that } be after \end{center}? – Dai Bowen Oct 6 '16 at 22:21
  • 2
    your last math expression $\in \mathbb{R} }$ has one { and two } but you should be using display math not center for equations. – David Carlisle Oct 6 '16 at 22:22
  • I did what you all said. Now, I only have one error message: ! File ended while scanning use of \color@b@x. <inserted text> \par <*> maths1.tex I suspect you have forgotten a }', causing me to read past where you wanted me to stop. I'll try to recover; but if the error is serious, you'd better type E' or `X' now and fix your file. ! Emergency stop. <*> maths1.tex *** (job aborted, no legal \end found) Here is how much of TeX's memory you used: [...] ! ==> Fatal error occurred, no output PDF file produced! – Henri Lils Oct 6 '16 at 22:31
  • You should read up about logical markup. Don't use manual centring and font size settings; rather, use the appropriate environment for what you're trying to do: equation for displayed equations, \maketitle to get the document title and so on. – David Richerby Oct 7 '16 at 9:19
  • Please use a more specific title for your question! – reinierpost Oct 7 '16 at 10:09
7

I'm not sure if there's a package which uses French colour names out of the box, so I've substituted red and yellow. Please note that color is very limited in the number of predefined colours it has, although you can define new ones as you like, and you can give them French names, or any name you want really.

But for the purposes of fixing this error, try this:

\documentclass{article}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsfonts}
\usepackage{color}

\begin{document}

\begin{center}
  {\large \textbf{COMMENT RÉSOUDRE UNE ÉQUATION ?}}
\end{center}

\fcolorbox{red}{yellow}{\parbox{\linewidth}{
    \begin{center}
      Résoudre l'équation (E):
      $(x^{2} + 1)^{2} = (x^{2} - 1)^{2}$
      d'inconnue $x \in \mathbb{R}$
    \end{center}
  }
}

\end{document}

I've moved your x inside $ ... $ for $x \in \mathbb{R}$ and tidied up some of your code formatting to make it easier to see where you went wrong.

Your main mistake was you needed \parbox{\linewidth}{foo} with braces around foo. You had mistakenly put your closing brace after \mathbb{R}, within $ ... $ and within the center environment.

You also had a } after \end{document}.

This should work, although I'll leave you to select the colours you want to use, as I have no idea what chamois is supposed to look like!

enter image description here

Also, consider using display math: \[ ... \]:

\documentclass{article}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{color}

\begin{document}

\begin{center}
  {\large \textbf{COMMENT RÉSOUDRE UNE ÉQUATION ?}}
\end{center}

\fcolorbox{red}{yellow}{\parbox{0.9\linewidth}{
    \[
      \text{Résoudre l'équation (E): }
      (x^{2} + 1)^{2} = (x^{2} - 1)^{2}
      \text{ d'inconnue } x \in \mathbb{R}
    \]
  }
}

\end{document}

enter image description here

  • 2
    « chamois » is ‘buff’ – it's the name of a kind of wild goat which lives in the Alps. – Bernard Oct 6 '16 at 23:52
  • @Bernard I see, thanks :) Nice answer, btw, I think I actually prefer yours :) – Au101 Oct 6 '16 at 23:58
  • I think they're complementary. You give more useful details for a beginner. – Bernard Oct 7 '16 at 0:01
7

You have two closing } wrongly placed. I suppose you want one of these: (as I don't know how the ‘brun’ and ‘chamois’ colours are defined, I replaced them with (hopefully) similar colours from the svgnames palette. Also, your \parbox can't have a width of \linewidth, otherwise it will overflow the rightmargin:

\documentclass[french, a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe]{geometry}%
\usepackage{amsfonts}
\usepackage[svgnames]{xcolor}
\colorlet{brun}{Brown}  
\colorlet{chamois}{Tan}  
\begin{document}

\begin{center}
\large \textbf{COMMENT RÉSOUDRE UNE ÉQUATION ?}
\end{center}

\noindent\fcolorbox{brun}{chamois}{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}
{\centering Résoudre l'équation (E):
$(x^{2} + 1)^{2} = (x^ {2} - 1)^{2}
$\ d'inconnue $ x \in \mathbb{R} $
}}
\bigskip

\noindent\fcolorbox{brun}{chamois}{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}
{\begin{center}%
 Résoudre l'équation (E):
$(x^{2} + 1)^{2} = (x^ {2} - 1)^{2}
$\ d'inconnue $ x \in \mathbb{R} $
\end{center}%
}}

\end{document}

enter image description here

5

If you wish to use your own colors, you can define them as shown in the code below, using \definecolor like this:

\definecolor{name}{color model}{values}

name = any name your color is called by.
color model = RGB, HTML, rgb, cmyk, gray
values = depends on model and can be either hex, integer or float values, see code.

\documentclass{article}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsfonts}

%extended color tables
\usepackage{xcolor}

%define custom colors here. I took some values which are close estimates.
\definecolor{chamois1}{RGB}{239,224,185}
\definecolor{chamois2}{rgb}{0.94,0.88,0.73} %percentage based
\definecolor{brun1}{cmyk}{0, 34, 90, 22}
\definecolor{brun2}{HTML}{#DEB887}

\begin{document}

\begin{center}
{\large \textbf{COMMENT RÉSOUDRE UNE ÉQUATION ?}}
\end{center}

\fcolorbox{brun}{chamois}
{\parbox{\linewidth}
    {
        some equation in here! use style as explained by others.
    }
}
\end{document}

Result: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.