11

I have a PStricks code and made some design in paint and converted to LaTeX code using Inkscape. Here is my MWE:

 \documentclass{standalone}
 \usepackage{graphicx,xcolor}
 \usepackage[svgnames,pdf]{pstricks}

 \begin{document}
 \psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
 \begin{pspicture}(1122.51968504,793.7007874)
 {
 \newrgbcolor{curcolor}{0.0 0.18 0.39}
 \pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
 {
 \newpath
 \moveto(0.21430135,613.28571969)
 \lineto(0.21430135,791.28569953)
 \lineto(564.28569449,791.28569953)
 \lineto(1124.35710236,791.28569953)
 \lineto(1124.35710236,752.28569953)
 \curveto(1124.35710236,726.58745197)(1124.0120315,713.28570709)(1123.34551181,713.28570709)
 \curveto(1122.78901417,713.28570709)(1110.33327874,714.38343307)(1095.66610394,715.72512756)
 \curveto(1047.23973543,720.15496063)(1031.79420472,720.78568819)(971.7463937,720.78568819)
 \curveto(911.02805669,720.78568819)(895.60410709,720.11690079)(854.04661417,715.68215433)
 \curveto(798.76191496,709.78253858)(761.94504567,702.99148346)(705.42568819,688.26837165)
 \curveto(627.87208819,668.06585197)(567.87405354,645.8808189)(430.12792441,586.47367559)
 \curveto(335.62666583,545.71717795)(298.91214614,530.42936693)(255.39842646,513.7168252)
 \curveto(195.55985008,490.73431181)(135.52230803,470.60330079)(75.53238803,453.40648819)
 \curveto(48.22059969,445.57723465)(8.88333846,435.28569449)(6.26950677,435.28569449)
 \lineto(0.21430135,435.28569449)
 \closepath
 }
 }
 \end{pspicture}
 \end{document}

enter image description here

  • I have renewed my answer, please look at it. – CarLaTeX Jan 7 '18 at 9:14
14

i assume that this image is some illustration, so the exact coordinates of is not the most important and can be later adjusted by trial. drawing straight lines is simple, for the curved lines i suggest to use controls macro:

(<coordinate 1>) .. controls + (<control point 1>) 
                         and + (<control point 2>) .. (<coordinate 2>)

where sign + denote relative position to coordinates.

enter image description here

\documentclass[tikz,margin=0pt]{standalone}
\definecolor{curcolor}{rgb}{0,0.18,0.39}

\begin{document}
    \begin{tikzpicture}
\fill[curcolor]
    (0,0) -| (12,-1.2)
    .. controls ++ (-0.5,0.1) and ++ (1,0) .. (10,-1)
    .. controls ++ (-3,0) and ++ (4,1) .. (0,-5) -- cycle;
\path(0,0) rectangle + (12,-8);% if needed
    \end{tikzpicture}
\end{document}
  • 4
    ...interesting... to date you have 444 posts using the phrase "Like this"... – Werner Jan 6 '18 at 6:33
  • @Werner, really? i newer count ... can you suggest some other (short) phrase? – Zarko Jan 6 '18 at 6:43
  • 4
    @Zarko Don't change. It's perfect! – DG' Jan 6 '18 at 9:42
  • 3
    @DG', :-), ... but number is fascinating. in time of Werner comment i had this week reputation 666 ... :-( – Zarko Jan 6 '18 at 9:47
  • @Zarko: My suggestion would be to add some more substance and explain what your code is all about. Why do you use controls? What is the syntax of controls? Perhaps highlight the reason for controls by the same drawing without it. – Werner Jan 6 '18 at 18:26
8

The PSTricks export from Inkscape is crap!

\documentclass{standalone}
\usepackage{pstricks}
\definecolor{curcolor}{rgb}{0.0,0.18,0.39}

\begin{document}
\psset{unit=.5pt}
\begin{pspicture}(1122,793)
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]{
 \psline(0,435)(0,791)(1124,791)(1124,713)(1122,713)
 \psbezier(1110,714)(1095,715)(1047,720)(1031,720)%
   (895,720)(854,715)(798,709)(761,702)(705,688)(627,668)(567,645)(430,586)%
   (335,545)(298,530)(255,513)(195,490)(135,470)(75,453)(48,445)(8,435)(0,435)}
\end{pspicture}

\qquad

\begin{pspicture}(1122,793)
\newrgbcolor{curcolor}{0.0 0.18 0.39}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]{
\psline(0,435)(0,791)(1124,791)(1124,713)(1122,713)
 \pscurve(854,715)(627,668)(430,586)(335,545)(255,513)(135,470)(0,435)}
\end{pspicture}

\end{document}

enter image description here

enter image description here

  • 1
    It's generally the case from drawing software… – Bernard Jan 6 '18 at 11:20
7

This answer does not try to improve the shape, but explains the translation from pstricks to TikZ:

  • The dimensions do not need to be specified, in many cases TikZ can calculate the bounding box from the elements on in the picture.

  • The color can be defined with the color (or xcolor) package:

    \definecolor{curcolor}{rgb}{0, .18, .39}
    
  • The units settings

    \psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
    

    can be done with options x and y, runit is not used:

    \begin{tikzpicture}[x=.5pt, y=.5pt]
    
  • A path is filled by \path[fill=curcolor] ...; or shorter:

    \fill[curcolor] ...;
    

    Solid fill is the default. A line is not drawn unless draw is added. This covers:

    \pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]{
      \newpath
      ...
    }
    
  • \moveto(12, 34) is implicitly done by specifying a coordinate:

    (12, 34)
    
  • \lineto(56, 78) becomes:

    -- (56, 78)
    
  • \curveto(1, 2)(3, 4)(5, 6) is specified by controls (see Zarko's answer). The first two points are the control points:

    .. controls (1, 2) and (3, 4) .. (5, 6)
    
  • \closepath:

    -- cycle
    

Full example:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{xcolor}

\definecolor{curcolor}{rgb}{0, .18, .39}

\begin{document}
\begin{tikzpicture}[x=.5pt, y=.5pt]
  \fill[curcolor]
    (0.21430135,613.28571969)
    -- (0.21430135,791.28569953)
    -- (564.28569449,791.28569953)
    -- (1124.35710236,791.28569953)
    -- (1124.35710236,752.28569953)
    .. controls (1124.35710236,726.58745197) and (1124.0120315,713.28570709)
                .. (1123.34551181,713.28570709)
    .. controls (1122.78901417,713.28570709) and (1110.33327874,714.38343307)
                .. (1095.66610394,715.72512756)
    .. controls (1047.23973543,720.15496063) and (1031.79420472,720.78568819)
                .. (971.7463937,720.78568819)
    .. controls (911.02805669,720.78568819) and (895.60410709,720.11690079)
                .. (854.04661417,715.68215433)
    .. controls (798.76191496,709.78253858) and (761.94504567,702.99148346)
                .. (705.42568819,688.26837165)
    .. controls (627.87208819,668.06585197) and (567.87405354,645.8808189)
                .. (430.12792441,586.47367559)
    .. controls (335.62666583,545.71717795) and (298.91214614,530.42936693)
                .. (255.39842646,513.7168252)
    .. controls (195.55985008,490.73431181) and (135.52230803,470.60330079)
                .. (75.53238803,453.40648819)
    .. controls (48.22059969,445.57723465) and (8.88333846,435.28569449)
                .. (6.26950677,435.28569449)
    -- (0.21430135,435.28569449)
    -- cycle
  ;
\end{tikzpicture}
\end{document}

Result

5

A simple solution with a sin function drawn with \draw plot. (You could refine the parameter to match your needs).

\documentclass[tikz]{standalone} 
\definecolor{curcolor}{rgb}{0,0.18,0.39} 
\begin{document} 
\begin{tikzpicture} 
\draw[color=curcolor, fill=curcolor] (-10, 7) -- 
    plot[domain=-10:22, samples=300] (\x,{5*sin(\x/11 r)}) -- (22,7) -- cycle; 
\path (-10, -10) rectangle ++(32,-7); 
\end{tikzpicture} 
\end{document}

enter image description here

4

There is a simple correspondence, though not absolutely exact (I think) between the pstricks and TikZ commands. (X) \lineto (Y) translates into (X) -- (Y) (inside a \draw ... environment) and (X) \curveto (Y) (Z) ... becomes (X) -- plot coordinates {(Y)(Z)...}. So

 \documentclass{standalone}
 \usepackage{tikz}

 \begin{document}
 \begin{tikzpicture}
 \definecolor{DeepBlue}{rgb}{0,0.18,0.39}
 \fill[DeepBlue,smooth] (0.00214, 6.13286) -- (0.00214, 7.91286) -- 
 (5.64286, 7.91286) -- (11.2436,   7.91286)--  (11.2436, 7.52286) -- (11.2436, 7.26587)--  plot coordinates{(11.2401,   7.13286) (11.2335, 7.13286) (11.2279, 7.13286) (11.1033,   7.14383) (10.9567, 7.15725) (10.4724, 7.20155) (10.3179,   7.20786) (9.71746, 7.20786) (9.11028, 7.20786) (8.95604,   7.20117) (8.54047, 7.15682) (7.98762, 7.09783) (7.61945,   7.02991) (7.05426, 6.88268) (6.27872, 6.68066) (5.67874,   6.45881) (4.30128, 5.86474) (3.35627, 5.45717) (2.98912,   5.30429) (2.55398, 5.13717) (1.9556, 4.90734) (1.35522,   4.70603) (0.75532, 4.53406)}
-- (0.48221, 4.45577) -- (0.08883,   4.35286) -- (0.0627, 4.35286) -- (0.00214, 4.35286);
 \end{tikzpicture}
 \end{document}

produces something which is very close to your screenshot. Other options to smoothen the contour are discussed e.g. here.

enter image description here

But since you seem to have produced the code with inkscape, you may look into the automatic conversion. I post this because I was unable to get svg2tikz installed. (Notice also that I divided your coordinates to make them tikZable.)

Another, arguably more beautiful way to go is to ask your favorite computer algebra system to find a parametrization of the contour. This yields

 \documentclass{standalone}
 \usepackage{tikz}

 \begin{document}
 \begin{tikzpicture}
 \definecolor{DeepBlue}{rgb}{0,0.18,0.39}
 \draw[domain=0.00214:11.22789,smooth,variable=\x,fill=DeepBlue] plot ({\x}, 
 {-6.9158922189150305 +1.866300006839081*\x - 
 0.10927417962900386*
  (-104.05234359678035 + 
   exp(0.6230737205554076*\x))*
  (1 - 0.14157109964187192*\x + 
   0.005184318196230514*\x^2)}) -- (11.22789,7.91286)--(0.00214, 7.91286) --cycle;  
 \end{tikzpicture}
 \end{document}

enter image description here

Of course, one may play with the curve, i.e. shift and rescale it, and thus make the parametrization prettier.

4

A code golfing with PSTricks.

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}
\definecolor{x}{rgb}{0,.2,.4}
\begin{document}
\pspicture(\psPiTwo,4)
\pscustom*[linecolor=x,algebraic]{\psplot{0}{TwoPi}{2-cos(x/2)}\psline(!TwoPi 4)(0,4)}
\endpspicture
\end{document}

enter image description here

  • \pscustom*[linecolor=x]{\psplot[algebraic]{0}{TwoPi}{2-cos(x/2)} \psline(\psPiTwo,4)(0,4)} – user2478 Jan 7 '18 at 10:35
1

If you have your desired shape in inkscape you could simply use the extension https://github.com/kjellmf/svg2tikz and directly export from inkscape to tikz.

\documentclass{standalone}
\usepackage{tikz}
\definecolor{c000080}{RGB}{0,0,128}

\begin{document}

\begin{tikzpicture}[yscale=-1.000000]
\path[fill=c000080] 
(0.0,0.0) -- 
(210.0,0.0) .. controls (210.0,0.0) and (210.0,0.0) .. 
(210.0,15.5) .. controls (111.8,15.5) and (112.9,69.3) ..
(0.0,69.6) -- cycle;
\end{tikzpicture}
\end{document}

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.