Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the simplest way to make coloured boxes with rounded corners in luatex? With xelatex I used pstricks and it was simple, but with luatex it is not working.

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

The simplest method is to use the mdframed or the tcolorbox package (example for tcolorbox: http://ctan.org/tex-archive/macros/latex/contrib/tcolorbox) package, which use TikZ. You can integrate with Lua as per the following MWE example, which uses both packages. It also runs the code and typesets the example. Please ensure you have the latest versions for all and run as LuaLaTeX (tcolorbox was updated recently).

enter image description here

I have used the same base code from another post of mine How can I produce vertical white space in a table with LuaLaTeX?, which I posted tonight. Have a look also at that post for unframed boxes (they look better to me).

\lstloadlanguages{[LaTeX]TeX, [primitive]TeX,Pascal}
\usepackage{luacode} % loads luatexbase as well
      showspaces=false,  % shows spacing symbol


-- example adapted from
-- http://rosettacode.org/wiki/Happy_numbers
function boxit(color, var, s)
 zz="\\mdframed[roundcorner=3pt, leftmargin=2cm,innertopmargin=0pt,innerbottommargin=0pt, innerleftmargin=0pt,innerrightmargin=0pt, innerlinewidth=0pt, middlelinewidth=0pt,outerlinewidth=1pt, outerlinecolor=red]"..var.."\\endmdframed"
 return zz
function digits(n)
  if n > 0 then return n \% 10, digits(math.floor(n/10)) end
function sumsq(a, ...)
  return a and a ^ 2 + sumsq(...) or 0
local happy = setmetatable({true, false, false, false}, {
      __index = function(self, n)
         self[n] = self[sumsq(digits(n))]
         return self[n]
      end } )
i, j = 0, 8
   i, j = happy[j] and (tex.sprint(boxit(violet, j, " ")) or i+1) or i, j + 1
until i == 17 --or j > 999
share|improve this answer
I would recommend tcolorbox. pstricks allows no page breaks so it's the nearest. –  Marco Daniel Mar 18 '12 at 18:42
@MarcoDaniel The post has both:) Can you help with the style to get it nearer to boxit in the link I posted in the answer? I am not very familiar with your package. –  Yiannis Lazarides Mar 18 '12 at 18:44
@YiannisLazarides: I compiled the tcolorbox example with lualatex and it just worked. –  Stephen Mar 18 '12 at 18:54
@Stephen -- Thanks for the test and the edit for the links. The tcblisting I used is one of the environments of tcolorbox. Great package. –  Yiannis Lazarides Mar 18 '12 at 18:59
tcolorbox is really nice, thank you very much! –  SadChi Mar 18 '12 at 19:17
show 1 more comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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