2

I need to put long text in an oval like this: enter image description here

I try to put a simply text inside an oval, but it does not work (the text overflows the oval). So I guess I need an oval around a text.

I have this code in METAFUN but I want to port it to TikZ:

% cover in METAFUN
\startuseMPgraphic{cover}
StartPage ;
fill Page withcolor white ;
pickup pencircle scaled 2mm ;
path p ; p := tensecircle(1cm,.75cm,.15cm) xsized(PaperWidth-2cm) ;
draw p shifted center Page withcolor .720green ;
StopPage ;
\stopuseMPgraphic
\defineoverlay[cover][\useMPgraphic{cover}]

% The first page
\starttext
\setupbackgrounds[page][background=cover]
\startstandardmakeup
{\raggedcenter
\vfill\startcolor[middleblue]{\switchtobodyfont[30pt] Title\par}\stopcolor
\blank[2*big]
\ \ \ \ \thinrule \ \ \ \
\blank[big]
{\switchtobodyfont[16pt]\sc Subtitle with long explanation\par}
\vfill
{\switchtobodyfont[14pt]{\sc Author}}\par}


\stopstandardmakeup
\setupbackgrounds[page][background=]
\stoptext

It has to be capable of treating with very long text. Example of non-wanted behaviour are these: enter image description here enter image description here

2 Answers 2

4

Previously, this answer contains the full shape definition. It has been moved to the ext.shapes.superellipse library of my tikz-ext package and can simply be loaded by

\usetikzlibrary{ext.shapes.superellipse}

A superellipse shape.

Keys:

  • superellipse x exponent,
  • superellipse y exponent,
  • superellipse step (the stepwidth of the plot-loop) and
  • superellipse exponent (sets both x and y exponent).

The anchors on the border are found trough intersections which takes a bit of time.

The radii evaluation is the same as for the ellipse shape which multiplies the values with √2. To fit a lot of text on a page we use a text width of 1/√2 * \linewidth and of that we subtract the inner xseps as well as the \pgflinewidth (so that even the line of the shape doesn't protrude into the margin.

text width=.7071067\linewidth-\pgfkeysvalueof{/pgf/inner xsep}*2-\pgflinewidth

I've also set align=flush center to get centered text that is not hyphenated.

Inside the node, the dimension \linewidth is a long as the text width is so we can use this directly for the horizontal \rule.

Even though, the whole tikzpicture is now as wide as \linewidth I'll still put it into the center environment which doesn't indent the line and is its own paragraph.

At the end of the preamble are some commands to show the vertical lines of the page. These are not needed otherwise.

Code

\documentclass{article}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepgflibrary{ext.shapes.superellipse}

% Begin: adjust frame of geometry
\usepackage[pass,showframe]{geometry}\usepackage{etoolbox}
\makeatletter
\preto\Gm@vrule{\color{red}}\let\Gm@hrule\@empty\let\Gm@hruled\@empty
\makeatother
% Begin: end frame of geometry

\begin{document}
\begin{center}
\tikz\node[draw=green, line width=2pt, superellipse, align=flush center,
  text width=.7071067\linewidth-\pgfkeysvalueof{/pgf/inner xsep}*2-\pgflinewidth
]{
  {\Huge\color{blue}Apunts de Matemàtiques
    per a l'Accés a la UIB per a majors de 25 anys\par}
  {\color{gray}\rule[.5ex]{\linewidth}{1pt}\par}
  {Teoria i exercicis per a la preparació de les
    ``Proves d'accés a la Universitat de les Illes Balears per a majors de
    25~anys i menors de 40~anys'' de l'assignatura de Matemàtiques\par}};
\end{center}
\end{document}

Output

enter image description here

6
  • What an answer!!!
    – JeT
    Commented Aug 21, 2022 at 20:55
  • 1
    Will/are you making your shapes available somewhere? It could be hard to find this answer in the future. Commented Aug 22, 2022 at 0:27
  • @Qrrbrbirlbel I get an error: Package gensymb Warning: Not defining \perthousand. Package gensymb Warning: Not defining \micro. (./01-portada.tex ! TeX capacity exceeded, sorry [input stack size=5000]. \pgf@selectfontorig ->\pgf@selectfontorig \nullfont l.9 {\Huge \color{blue}Apunts de Matemàtiques per a l'Accés a la UIB per a ... Commented Aug 22, 2022 at 7:38
  • 1
    That's a warning, not an error. A warning by the package gensymb which has nothing to do with my answer. In fact, I get the same message if I just put your text in a document without any TikZ to begin with. Also, look into the siunitx package which is much more advanced than a 20 year old one. Commented Aug 22, 2022 at 9:08
  • @Qrrbrbirlbel The text passes the paper (see my original post, modified) Commented Aug 22, 2022 at 10:05
5
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[
declare function={
  sx(\t)= a*cos(\t r)^(2/n);
  sy(\t)= b*sin(\t r)^(2/n);
  a=5;
  b=4;
  n=2.5;
}]
\draw[green!80!black, line width=3pt, variable=\t, domain=0:pi/2] plot({sx(\t)},{sy(\t)}) -- plot({-sx(pi/2-\t)},{sy(pi/2-\t)}) -- plot({-sx(\t)},{-sy(\t)}) -- plot({sx(pi/2-\t)},{-sy(pi/2-\t)}) -- cycle;
\node[blue, yshift=0.6cm]{\Large Title};
\node[yshift=-0.5cm]{Subtitle with long explanation};
\draw (-4,0) -- (4,0);
\end{tikzpicture}
\end{document}

Green superellipse with text

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[
declare function={
  sx(\t)= a*cos(\t r)^(2/n);
  sy(\t)= b*sin(\t r)^(2/n);
  a=15;
  b=10;
  n=2.2;
}]
\draw[green!80!black, line width=4pt, variable=\t, domain=0:pi/2] plot ({sx(\t)},{sy(\t)}) -- plot({-sx(pi/2-\t)},{sy(pi/2-\t)}) -- plot({-sx(\t)},{-sy(\t)}) -- plot({sx(pi/2-\t)},{-sy(pi/2-\t)}) -- cycle;
\node[blue, yshift=0.8cm]{\Huge Apunts de Matemàtiques per a l'Accés a la UIB per a majors de 25 anys};
\node[yshift=-0.5cm]{Teoria i exercicis per a la preparació de les ``Proves d'accés a la Universitat de les Illes Balears per a majors de 25 anys i menors de 40 anys'' de l'assignatura de Matemàtiques};
\draw (-14,0) -- (14,0);
\end{tikzpicture}
\end{document}

Super ellipse with long text

3
  • @hperkristiansen Thanks, but it does not work with Title=\Huge Apunts de Matemàtiques per a l'Accés a la UIB per a majors de 25 anys and Subtitle=Teoria i exercicis per a la preparació de les ``Proves d'accés a la Universitat de les Illes Balears per a majors de 25 anys i menors de 40 anys'' de l'assignatura de Matemàtiques Commented Aug 21, 2022 at 17:16
  • It works fine for me. What is not working? Commented Aug 21, 2022 at 17:33
  • @hperkristiansen I modified the original post and you see what I get. I use it within titlepage You can see what really want in my repo (other project making in \CONTEXT so I cannot use code because it uses metafun) Commented Aug 22, 2022 at 7:27

You must log in to answer this question.

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