0

This is my code:

% XeLaTeX
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox}
\usepackage{environ}
\setlength\parindent{0pt}

\usepackage{array}
\usepackage{tabularx}

\newenvironment{solution}
    {
    \begin{tcolorbox}
    \begin{tabularx}{\textwidth}{p{0.7cm}X}
    }
    {
    \end{tabularx}
    \end{tcolorbox}
    }
\def\fakta#1{\stepcounter{fakta} F{\arabic{fakta}}: & #1 \\}
\def\contoh#1{\stepcounter{contoh} C{\arabic{fakta}}{\alph{contoh}}: & #1 \\}
\def\huraian#1{\stepcounter{huraian} H{\arabic{fakta}}{\alph{huraian}}: & #1 \\}

and I'm trying to do something like

\begin{solution}
\fakta{blablabla}
\end{solution}

but it doesn't work and errors keep coming out. Why?

UPDATE:

\newenvironment{solution}
  {
  \tabularx{\textwidth}{lX}
  }
  {
  \endtabularx
  }

^this works, but not this:

\newenvironment{solution}
  {
  \begin{tcolorbox}
  \tabularx{\textwidth}{lX}
  }
  {
  \endtabularx
  \end{tcolorbox}
  }
3
  • 1
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Oct 7, 2019 at 4:48
  • @StefanPinnow I kind of found a solution to this should i delete it :) Oct 7, 2019 at 4:50
  • 1
    It's best to post your solution here, rather than deleting the post... so that anyone who gets stuck with a problem like this gets help from your solution.
    – Partha D.
    Oct 7, 2019 at 4:58

2 Answers 2

2

In both cases you get the error

! File ended while scanning use of \TX@get@body.

In the first case LaTeX is looking for \end{tabularx}, which it doesn't find because it's hidden inside \end{solution}.

In the second case \tabularx makes LaTeX look for \end{tcolorbox}, which is the parent environment when \tabularx is processed, but the problem is the same, because \end{solution} is not a valid terminator.

The proper solution is to use \newtcolorbox:

\documentclass[a4paper,12pt]{article}

\usepackage[table]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}

\newtcolorbox{solution}{tabularx=p{0.7cm}X}

\setlength\parindent{0pt}

\begin{document}

\begin{solution}
A & B
\end{solution}

\end{document}
1

I found an alternative way, by "reconstructing" tcolorbox using framedmd:

% in Preamble: \usepackage[framemethod=TikZ]{mdframed}

\newenvironment{solution}
  {
  \mdframed[roundcorner=7pt,backgroundcolor=gray!10,linewidth=1.5pt]
  \tabularx{\textwidth}{lX}
  }
  {
  \endtabularx
  \endmdframed
  }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .