Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?J=c3=b6rg_Buchholz?= Newsgroups: comp.graphics.apps.gnuplot Subject: Re: space between sign and digit Date: Wed, 11 Jul 2018 14:16:17 +0200 Organization: A noiseless patient Spider Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 11 Jul 2018 12:16:17 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="dc26474d1c6b47379bccbe64355446fa"; logging-data="6364"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XrXGLnaxNkkEE04ol1a0HPFt5KhO7wMY=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:8GO/CLmhI50GSCZaRz54eqbjoh0= In-Reply-To: Content-Language: en-GB Xref: csiph.com comp.graphics.apps.gnuplot:3998 On 11.07.2018 10:00, Karl Ratzsch wrote: > Am 11.07.2018 um 08:52 schrieb Jörg Buchholz: >> Hello, >> >> I would like to print a function in the key like this: >> >> f11(x) = -2.56·x - 103.63 >> >> I use the following code in the plot command for that: >> >> f11(x) lt 2 lw 4 dt 4 t sprintf("f11(x) =%6.2f·x%+7.2f",a,b11) >> >> That means, that I use the sign from the format specifier as plus sign >> or minus sing in the printed function. But than I don't have a space in >> front of the second number. The second number can be positive or negative. > > sprintf() can't add an extra space in there i think. Following uses the > ternary operator on b11 to check which sign character is needed > > plot f11(x) lt 2 lw 4 dt 4 t \ > sprintf("f11(x) =%.2f·x %s %.2f",a,b11<0?"-":"+",abs(b11)) > Interesting solution. On more complex functions the code is a bit long. But on the other hand I can use a thin space for better looking at the print out. Thanks Jörg