Display custom widget, added as a shortcode in the correct place

The output from a shortcode should be returned, not echoed. Echoing output in a shortcode will have unexpected output like you are seeing. the_widget() echos its output which is causing the issue. Unfortunately there is no similar function for returning the wdget output.

Luckily you can make use of a output buffer to overcome this issue. You can try something like this : (CAVEAT: Untested)

function show_custom_widget() {
    ob_start(); 
    the_widget( 'YOUR CUSTOM WIDGET' ); 
    $contents = ob_get_clean(); 
    return $contents;
}
add_shortcode( 'custom-widget', 'show_custom_widget' );